Thursday, September 28, 2006
Memory leaks in .Net Part #1
"Hi! There are no memory leaks in .Net! It has that great garbage collector everyone's talking about! And the dispose pattern and all that".
Not very likely that a person actually uttered this, but it’s a great start for a discussion. I’ll start mentioning some normal
miss
conceptions about GC, Dispose and that "stuff":
The garbage collector cleans up everything you keep laying around and you don’t need to worry about it.
If you just do your cleanup in Dispose the GC will call dispose for you.
If you really want to be sure, do your cleanup in the destructor and your home free.
Nice! Lets just do this and we can all go home… Or you can read on…:
The garbage collector cleans up everything you don’t use anymore. That is all objects not referenced by your running program.
If you do your cleanup in Dispose, YOU have to remember to call it! Not only that, if you use objects that have Dispose methods, you need to call them as well!
You can do cleanup in the destructor, but it’s much more efficient to use the Dispose pattern. More on this later.
I think most of us know that the garbage collector only releases objects with no running references to it. What’s interesting though is that not everyone knows that you
have to call Dispose on all objects that have a Dispose method!
I can not emphasize this enough (even though I tried with bold text).
You have a gene in your body as developer to call Close methods (on file handles, data connection etc), but no one ever mentioned Dispose for you. Or you where told that the GC call Dispose for you, or something else that sounded good at the moment.
.Net
|
MemoryLeaks
Thursday, September 28, 2006 12:00:00 AM (W. Europe Standard Time, UTC+01:00)
Disclaimer
|
Comments [0]
|
Comments Rss
|
Related posts:
New features in TFS2008 SP1
Pex: Automated Exploratory Testing for .Net
Are you deploying applications to Windows Vista, and doing ok?
The history behind .Net User Groups
ClickOnce - Server Deployment
Are you developing software with a keyboard or mouse?
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page
Remember Me
Comment (Some html is allowed:
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u
) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.
Live Comment Preview
Me
About
Contact
Aggregate Me!
Rss
Comments
Categories
.Net (31)
Agile (19)
Ajax (5)
Blogging (9)
Books (1)
BPEL (1)
CSharp (3)
DasBlog (4)
Database (2)
Deployment (5)
Events (25)
ExtremeProgramming (1)
Fun (3)
Gadgets (3)
IIS (5)
Java (1)
Linq (2)
MemoryLeaks (5)
Microsoft (30)
NDC (2)
NNUG (22)
Other (8)
Patterns (1)
Scrum (11)
Silverlight (4)
Software (16)
TeamManagement (8)
TechEd (7)
Testing (4)
Tools (15)
TvGuide (1)
Vista (14)
VisualStudio (12)
WCF (6)
Web (10)
Windows (6)
Work (12)
Workflow (2)
Navigation
Norwegian .Net User Group
NNUG Bergen
NNUG Bergen Meetings (Rss)
NNUG National News (Rss)
Blogroll
Anders Norås
Bård Strøm (Brad Storm)
Einar Ingebrigtsen
Fredrik Kalseth
Gøran Hansen
John Arthur Berg
Jonas Follesø
Per Ove Joakimsen
Rune Grothaug
Sondre Bjellås
Thomas Eyde
Torbjørn Marø
Trond Aarø
On this page....
Archives
July, 2008 (2)
June, 2008 (7)
May, 2008 (7)
April, 2008 (5)
March, 2008 (3)
February, 2008 (9)
January, 2008 (3)
December, 2007 (4)
November, 2007 (10)
October, 2007 (10)
September, 2007 (2)
August, 2007 (6)
July, 2007 (6)
June, 2007 (3)
May, 2007 (2)
April, 2007 (8)
March, 2007 (6)
February, 2007 (5)
January, 2007 (10)
December, 2006 (9)
November, 2006 (5)
October, 2006 (8)
September, 2006 (5)