Garbage collection question

A

Alpha83

Using .NET 2.0 / winforms. Some of our .NET classes, call some
unmanaged windows dll's. See some samples below -

<<
System.Runtime.InteropServices.DllImport("gdi32.dll"),

System.Runtime.InteropServices.DllImportAttribute("user32.dll").
Once these classes are instantiated and done being used, does the
garbage collector successfully gc them or will there be a problem in
some of these classes that use these non .NET dlls'. If so, how do we
garbage collect them.


Thanks.
 
B

Bob Powell [MVP]

Any managed class that uses unmanaged code should implement the dispose
pattern correctly.

See IDisposable and the various discussions on Dispose and deterministic
finalization.

You also need to respect the semantics of the API used. For example when
using GDI via interop you will still need to obey the rules of graphics
resource handle use and destruction.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top