One thing that’s a little peculiar with the Brep API is that you’re actually forcing a Dispose() on objects that are properties of the Brep object itself (objects that are instantiated when you access the property). That doesn’t always seem right – you would expect the using block around the Brep object to force a Dispose() on all associated objects created/exposed via its properties – but this a quirk of the Brep API that needs special attention, and a big reason the GC-driven finalisation of unmanaged objects seems to rear its ugly head more often when it’s used.
if you're not sure about the need to dispose something, just check its AutoDelete property. If it's false, then the odds are that you are either not supposed to delete it, or don't need to.
Kean, this is more directed at Fenton's advice regarding Dispose(), but neither his nor any of your posts on this topic so much as graze one important aspect of the question, which is the DisposableWrapper's AutoDelete property.
If this property is false, the wrapped native object is not deleted when its managed wrapper is disposed, and disposing a managed wrapper whose AutoDelete property is false, is both pointless and a source of code obfuscation.
And, if one is going to check the value of this property and use it as a guide for deciding to Dispose the managed wrapper, then one must remember that the managed wrapper can change its value depending on certain conditions. For example, the Database managed wrapper sets this property to true only when the wrapped AcDbDabase was created via a call to ReadDwgFile(). For databases that are open in the drawing editor, the value of AutoDelete is false.
I think it's a bit silly for everyone to be debating this issue when the value of that property literally and definitively answers that question for many (but not all) objects, don't you agree?
If we're going to debate the question of 'To Dispose or not to Dispose', it might help if everyone including the audience, become a bit more familiar with the inner workings of DisposableWrapper, and the fact that any managed wrapper that represents a native object that derives from AcRxObject, must derive from DisposableWrapper, regardless of whether it must be disposed or not.
if you're not sure about the need to dispose something, just check its AutoDelete property. If it's false, then the odds are that you are either not supposed to delete it, or don't need to.
Does that mean this would be acceptable in all cases where you are deleting an object?Code - C#: [Select]
if ( MyObject.AutoDelete ) { MyObject.Delete(); }
I have never understood the AutoDelete property and your description makes it seem counter-intuitive i.e. if AutoDelete is false it is automatically handled? It seems it should be the other way around unless I am missing something.
This was a comment I just posted on Kean's blog, regarding his analysis on this subject.Quote
Kean, this is more directed at Fenton's advice regarding Dispose(), but neither his nor any of your posts on this topic so much as graze one important aspect of the question, which is the DisposableWrapper's AutoDelete property.
If this property is false, the wrapped native object is not deleted when its managed wrapper is disposed, and disposing a managed wrapper whose AutoDelete property is false, is both pointless and a source of code obfuscation.
And, if one is going to check the value of this property and use it as a guide for deciding to Dispose the managed wrapper, then one must remember that the managed wrapper can change its value depending on certain conditions. For example, the Database managed wrapper sets this property to true only when the wrapped AcDbDabase was created via a call to ReadDwgFile(). For databases that are open in the drawing editor, the value of AutoDelete is false.
I think it's a bit silly for everyone to be debating this issue when the value of that property literally and definitively answers that question for many (but not all) objects, don't you agree?
If we're going to debate the question of 'To Dispose or not to Dispose', it might help if everyone including the audience, become a bit more familiar with the inner workings of DisposableWrapper, and the fact that any managed wrapper that represents a native object that derives from AcRxObject, must derive from DisposableWrapper, regardless of whether it must be disposed or not.
So, am I to understand that the AutoDelete property is really in reference to the underlying unmanaged object? i.e. if AutoDelete is false, the unmanaged object doesn't get deleted when the wrapper is disposed. This makes sense in that the unmanaged object is not automatically deleted when its wrapper is disposed.
However, doesn't that mean that the unmanaged object should be deleted? Will it result in memory leaks if it is not?
This was a comment I just posted on Kean's blog, regarding his analysis on this subject.Quote
< .. >
If we're going to debate the question of 'To Dispose or not to Dispose', it might help if everyone including the audience, become a bit more familiar with the inner workings of DisposableWrapper, and the fact that any managed wrapper that represents a native object that derives from AcRxObject, must derive from DisposableWrapper, regardless of whether it must be disposed or not.
This was a comment I just posted on Kean's blog, regarding his analysis on this subject.Quote
Kean, this is more directed at Fenton's advice regarding Dispose(), but neither his nor any of your posts on this topic so much as graze one important aspect of the question, which is the DisposableWrapper's AutoDelete property.
If this property is false, the wrapped native object is not deleted when its managed wrapper is disposed, and disposing a managed wrapper whose AutoDelete property is false, is both pointless and a source of code obfuscation.
And, if one is going to check the value of this property and use it as a guide for deciding to Dispose the managed wrapper, then one must remember that the managed wrapper can change its value depending on certain conditions. For example, the Database managed wrapper sets this property to true only when the wrapped AcDbDabase was created via a call to ReadDwgFile(). For databases that are open in the drawing editor, the value of AutoDelete is false.
I think it's a bit silly for everyone to be debating this issue when the value of that property literally and definitively answers that question for many (but not all) objects, don't you agree?
If we're going to debate the question of 'To Dispose or not to Dispose', it might help if everyone including the audience, become a bit more familiar with the inner workings of DisposableWrapper, and the fact that any managed wrapper that represents a native object that derives from AcRxObject, must derive from DisposableWrapper, regardless of whether it must be disposed or not.
Strange - I didn't get that comment through.
Tony, et al
Regarding autoDelete :
Under what circumstances would the autoDelete property be false ?
The constructors for (say) a line sets the property to true through the base class.
Just an aside.
It pleases me immensely to see the level of discussion on these subjects.
Thanks to all who are participating and attempting to clear up concepts that have been in dispute for years.
Regards,
Kerry