List Info

Thread: Garbage Collect & WeakReferences




Garbage Collect & WeakReferences
user name
2006-11-18 13:24:11
We use a third party COM component, which seems to have
troubles of
closing its files. I called Marshal.FinalReleaseComObject to
release
the COM object asap when I am done with it, but it still
seems to leak
its open files...

Contacted support and this is what they came with:

//-----------
//might be a bit overly explicit but a WeakReference will
not survive
//a garbage collection
WeakReference wkref = new WeakReference(comRef); comRef =
null;
GC.Collect(GC.GetGeneration(wkref));
//-----------

To me this seemed nonsense (the use of WeakRef), so I
altered the code into

int generation = GC.GetGeneration(comRef);
Marshal.FinalReleaseComObject(comRef);
comRef = null;
GC.Collect(generation);

but still, the com object is leaking its files...

Contacted support again, and they really want me to use code
sample
with the WeakReference...
I was about to send them an harsh email, but counted till 10
and typed
this email...

Would the use of WeakReference actually make any difference?
I dont
think so, but maybe I am wrong...

// Ryan

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Garbage Collect & WeakReferences
user name
2006-11-18 15:08:59
On 11/18/06, Ryan Heath <ryan.q.heathgmail.com> wrote:
>
> Would the use of WeakReference actually make any
difference?


No.

--
Brad Wilson
http://www.
agileprogrammer.com/dotnetguy/
http://www.fl
ickr.com/photos/dotnetguy/

"If programmers got paid to remove code from software
instead of writing new
code, software would be a whole lot better."
  - Nicholas Negroponte

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )