vtkCocoaRenderWindow should not create an NSAutoreleasePool
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
An autorelease pool is created in vtkCocoaRenderWindow's constructor and released in the destructor. The problem with this autorelease pool: any objects (including all objects that have nothing to do with VTK) created after this constructor are added to this autorelease pool and are never released until this VTK window is deleted.
In a native Mac application one uses many autoreleased objects and they cannot be correctly released (at small time intervals) when a VTK window is opened and suddenly when a VTK window is closed many autoreleased objects are deleted, including some objects that should not be deleted during this process, generating random crashes. If I remove this autorelease pool, the problems disappear.
I think the reason the pool is even created is this: most apps that use vtkCocoaRenderWindow.mm are not true cocoa apps, that is, they never call NSApplicationMain(), so as a workaround, an autorelease pool is created. For real cocoa apps, this is a pain.
I believe the best solution is to not create the autorelease pool and instead call the NSApplicationLoad() function. It is described like so "If NSApplication is not already initialized, initializes it and sets up event handlers for Cocoa. You typically call this before calling other Cocoa code in a plug-in loaded into a primarily Carbon application. A return value of YES indicates that NSApplication was successfully initialized for the Carbon application".
I am testing this solution and will submit a patch.