Click to See Complete Forum and Search --> : Question about Class and memory usage


rjbroldan
January 27th, 2010, 08:35 PM
Hi everyone,

I am a beginner programmer.

Does a the size of the class affect the memory usage of the application? is it better to break big classes into smaller classes or just group them up into one big class. thanks

rjbroldan
January 27th, 2010, 10:10 PM
just to make things a bit clearer, i have a utilily class that contains various functions for database dependency checkings and datasource substitutions (for datagridviews etc). i am wondering if whether breaking each of these functions into smaller classes rather having them in one chunky class would boost the application performance even by a little bit (or maybe save some memory usage). This thought came into my head because most of the time i am instantiating this class just to use one or two functions inside it. The rest of the functions will never get used during that class life cycle (sorry if i get some terminologies wrong here but i hope i get the point accross).

thanks in advance.

Craig Gemmill
January 28th, 2010, 03:36 PM
Well, it depends.

Every time you create an instance of the class, you're basically creating a pointer to the class definition. You're not actually creating a copy of the class each time. With that being said, if your class has any value –type variables or variables with a value, then each instance of those variables will eat up space.

A good practice for utility classes is to create a Singleton instance, or use static ("shared") methods that can be used without creating an instance of the class first.

An example of static methods:


Public Class Utility

Public Shared Function Foo() As String
'Do something
End Function

Public Shared Function Foo2() As String
'Do something
End Function

End Class


And, you can use that class without creating an instance:

Utility.Foo()