amirsalah / manageditk

Automatically exported from code.google.com/p/manageditk
Other
0 stars 0 forks source link

AddAnyEventObserver() call in itkImage.Allocate() prevents finalization #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create an itkImage, call SetRegions(...) and Allocate().
2. Set a break point on the finalizer. If you do not have debugging access to 
the source code, for example, if you 
use the pre-compiled assemblies, create a "class itkImage_Test : itkImage_F3". 
Within thie class, create a "public 
itkImage_Test() : base(itkPixelType.B, 3)" constructor and override the 
finalizer in order to set a break point.
3. "Forget" to properly Dispose() the itkImage before leaving the scope of the 
managed variable.

What is the expected output? What do you see instead?
I would expect the garbage collector to find out about the orphaned managed 
object and to finalize it. However, 
this never happens (until the last line of code has been executed, of course, 
by which time all objects are 
finalized by default). This can lead to memory leaks.

What version of the product are you using? On what operating system?
pre-compiled assemblies: ManagedITK-bin-x86-3.14.0.0.zip
self-built: revision 15 from SVN repository
Windows 7 x64, VS 2008 SP, compiling for x86

Please provide any additional information below.
It seems that itkImage.Allocate() calls itkImage.AddAnyEventObserver(). 
Apparently, this creates some kind of link 
between the managed itkImage and some other code-accessible object, so that the 
itkImage is never really 
"orphaned".

It is interesting to note that calling itkImage.RemoveAllObservers() after 
allocation can solve this problem; that 
is, some time after leaving the scope of the itkImage, the finalization of the 
managed object indeed happens.

Original issue reported on code.google.com by mr.ber...@gmail.com on 6 Jun 2010 at 12:27

GoogleCodeExporter commented 8 years ago
Two typos:
- thie class --> this class
- itkPixelType.B --> itkPixelType.F

Original comment by mr.ber...@gmail.com on 6 Jun 2010 at 12:39