dispose string literals
-
i am doing memory profiling of my application it shows many string literals staying in memory after closing the forms where they were used. Can anyone plz suggest, what is alternative to string literals because it dont get disposed and increase memory on opening the forms. Thanks Milan:confused::confused:
-
i am doing memory profiling of my application it shows many string literals staying in memory after closing the forms where they were used. Can anyone plz suggest, what is alternative to string literals because it dont get disposed and increase memory on opening the forms. Thanks Milan:confused::confused:
-
String literals are never disposed. They are compiled into the static data of the assembly, and when you create a string object from a literal, you just get a reference to the static data.
--- single minded; short sighted; long gone;
then why the profiler is showing me it in memory
-
then why the profiler is showing me it in memory
Milan@DIGICorp wrote:
then why the profiler is showing me it in memory
Where else would it be?
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
Milan@DIGICorp wrote:
then why the profiler is showing me it in memory
Where else would it be?
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
i mean that after closing the form where i have used string literal they dont realease memory they have used they are of age 40-45 and more. i think they should be removed as i close the form or the next gc call
-
i mean that after closing the form where i have used string literal they dont realease memory they have used they are of age 40-45 and more. i think they should be removed as i close the form or the next gc call
I haven't done the profiling to test this, but there is a theoretical possibility that the static strings will hang around in memory until the assembly that they are loaded from is unloaded. This could be your .EXE or a .DLL that your .EXE loads. If they are in the .EXE, then they'll live for the entire duration your app is running. If in a .DLL, they'll live only so long as when the AppDomain that loaded the .DLL unloads. Again, if your .DLL is not loaded into a seperate AppDomain that you created, they'll live for as long as your application is running. I can also see the possibility that static strings will never go away, so long as your app is loaded. This is because static information exists without an instance of the class that defined them being created. They exist all the time.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
i mean that after closing the form where i have used string literal they dont realease memory they have used they are of age 40-45 and more. i think they should be removed as i close the form or the next gc call
As I said, the string literals is part of the static data in the assembly. They are loaded when the assembly is loaded, and they are only removed from memory when the assembly is unloaded. Using a string literal doesn't use any memory. The memory is already allocated for the static data. Using a string literal doesn't allocate any more memory, so there is no memory to free when you don't use the string any more.
--- single minded; short sighted; long gone;