Multiple Windows and Memory Leakage

Discussion in 'Mac Programming' started by BadWolf13, Nov 18, 2010.

  1. macrumors 6502

    Joined:
    Dec 17, 2009
    #1
    I've got an app with multiple windows that will often be opened for some time and then closed. So watching the memory usage of these windows and the window controllers is important to me. Here's the catch. I put an NSLog statement in the dealloc, which doesn't ever get printed in the console. I assumed that this meant that my window and window controller weren't being deallocated.

    On the other hand, I just use the Leak Instrument on the app today. When I opened the second window, it shows 1 instance of my NSWindowController subclass, and when I close that window, it shows 0 instances of my NSWindowController subclass, and that no memory is being used by this class.

    Don't these two observations contradict each other?
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    My guess is you're either reading Leaks wrong, or you have Garbage Collection enabled where finalize is called instead of dealloc.
     
  3. thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #3
    I'm using garbage collection. I just didn't realize that it called something else instead of dealloc. Should I override finalize to make sure that it releases its internal objects?
     
  4. macrumors newbie

    Joined:
    Nov 3, 2010
    #4
    No. Reread the garbage collection documents. The point of finalize is NOT to duplicate the dealloc method. You should only clean up NON GC'd resources in the finalize method as a last resort. Even then, finalize is not necessarily guaranteed to be called.
     
  5. macrumors 68000

    Sydde

    Joined:
    Aug 17, 2009
    #5
    Does the Leak Instrument even do anything under GC?
     

Share This Page