dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]lesson in dispose


From: Marcus
Subject: Re: [DotGNU]lesson in dispose
Date: Sun, 16 Nov 2003 12:29:19 -0600
User-agent: KMail/1.5.93

I hope that I don't offend anyone with my unsolicited advice on freeing 
unmanaged resources. I don't pretend to know the programming details about 
SWF in particular.

It's easy to free unmanaged resources prematurely. Specifically, if a managed 
object contains a reference to an unmanaged object but there other references 
to the unmanaged object elsewhere, it's not yet safe to free the unmanaged 
object.

I'm in the process of altering the memory management policies in my project 
because of this. Here is an example of how things were going wrong:

A QTable (spreadsheet-like widget) was being created. One method obtained a 
reference to the header-row -- a QHeader -- and stored it in a local 
variable. After the method returned, the finalizer for the QHeader variable 
got called, which freed the unmanaged QHeader. Unfortunately, the QTable was 
still being used, even though its header row was destroyed. So trying to 
manipulate the header row caused very strange behavior.




On Sunday 16 November 2003 12:07 pm, Neil Cawse wrote:
> Thanks.
>
> If we implement a class in pnetlib that has no managed resources but ms
> has implemented IDispose because they use unmanaged resources - a case
> that is common, then we need to just do:


reply via email to

[Prev in Thread] Current Thread [Next in Thread]