Windows Develop Bookmark and Share   
 index > Windows Forms General > Memory question - exiting a Winform app that uses static classes
 

Memory question - exiting a Winform app that uses static classes

Kind of a noob question. Lets say you have your form class and another static class containing a static generic list of objects. When the form is closed (as the application exits) What happens to the variables/ generic list in the static class. Will the memory of the objects in the static list be returned to the O.S. or do I need to perform some kind of cleanup like calling list.clear()? I want to know if not doing so will result in memory that cannot be reclaimed.

cyrix86  Tuesday, October 06, 2009 7:00 PM
All of the memory used by your process, including memory stored in static objects, will be reclaimed by the operating system automatically when your process exits.  You don't need to explicitly clear the objects.

The main time when it is important to cleanup static objects is if they're using some external resource - and the resource may not be released automatically, or at least not instantly, when the operating system tears down your application.  This is fairly rare, though, since memory and handles, etc, are all reclaimed automatically.

Reed Copsey, Jr. - http://reedcopsey.com
  • Marked As Answer bycyrix86 Tuesday, October 06, 2009 7:25 PM
  •  
Reed Copsey, Jr.  Tuesday, October 06, 2009 7:04 PM
All of the memory used by your process, including memory stored in static objects, will be reclaimed by the operating system automatically when your process exits.  You don't need to explicitly clear the objects.

The main time when it is important to cleanup static objects is if they're using some external resource - and the resource may not be released automatically, or at least not instantly, when the operating system tears down your application.  This is fairly rare, though, since memory and handles, etc, are all reclaimed automatically.

Reed Copsey, Jr. - http://reedcopsey.com
  • Marked As Answer bycyrix86 Tuesday, October 06, 2009 7:25 PM
  •  
Reed Copsey, Jr.  Tuesday, October 06, 2009 7:04 PM

You can use google to search for other answers

Custom Search

More Threads

• Print without Print DialogBox
• Insert,delete,update records in excel sheet
• How to get more info about port using System.IO.Ports.SerialPort
• problem reading an XLS into a datagridview
• color coding
• assembly - version extraction
• mshtml editing in vb
• Ugly Fonts
• How to keep a ToolStripDropDownButton always visible ?
• Tooltip