Click here to Skip to main content

Always dispose a form

Some time ago, we noticed that in one of our projects the size of memory of our application is growing and it never decreased.After some checking and testing we realized that even if we have a local reference to a form, if we haven't  disposed it explicitly it will remain on the stack and never
Sign Up to vote bad good
Add a reason or comment to your vote: x
Votes of 3 or less require a comment
See more: C#Windows

Some time ago, we noticed that in one of our projects the size of memory of our application is growing and it never decreased.

After some checking and testing we realized that even if we have a local reference to a form, if we haven't  disposed it explicitly it will remain on the stack and never be collected.  

So now, instead of writing this:

new usersDialog().ShowDialog()

We write: 

using(var dlg=new usersDialog())
    dlg.ShowDialog();
Posted 18 Nov '09
Edited 23 Nov '09


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Your Filters
Interested
Ignored
     
  1. SAKryukov (1,325)
  2. OriginalGriff (1,090)
  3. Abhinav S (495)
  4. thatraja (434)
  5. Rahul Dhoble (255)
  1. SAKryukov (9,459)
  2. Christian Graus (5,960)
  3. OriginalGriff (4,633)
  4. Abhinav S (4,335)
  5. thatraja (4,269)

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralForms Should Be Garbage Collected Fine Pinmemberaspdotnetdev16:42 18 Nov '09  
GeneralRe: Forms Should Be Garbage Collected Fine Pinmembersupercat910:13 19 Nov '09  
GeneralGood point, but typo in headline. Pinmembersupercat97:01 18 Nov '09  
GeneralRe: Good point, but typo in headline. Pinmemberaspdotnetdev16:18 18 Nov '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 23 Nov 2009
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid