Re: C# memory problem: no end for our problem ?

T

Ted Miller

Isn't this what GC.WaitForPendingFinalizers is for?

For example I use an external COM object over which I have no control, that
keeps a file open for exclusive access. When the COM object is destroyed,
the file is released. Fine in COM but the rest of my C# program wants to
open that file for read access once I've finished using the COM object to
manipulate the file.

The following:

MyComObject obj = new MyComObject("filename");
//...
obj = null;
GC.Collect();

does not work reliably, but the addition of

GC.WaitForPendingFinalizers()

seems to do the trick.

--
 

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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top