Memory management issues/leaks

Discussion in 'Mac Programming' started by pcwiz, Aug 17, 2009.

  1. pcwiz macrumors member

    Joined:
    May 28, 2008
    #1
    Hi,

    I have an Objective-C/Cocoa app with garbage collection enabled. To check for memory leaks I first ran it through Instruments and it did find some leaks. There was no information on where the leaks were coming from, so I used another tool, AnalysisTool (basically a front end for the Clang Static Analyzer) to check my code for memory issues. It found some leaks and I fixed all of them, however Instruments still reports leaks.

    Further complicating the problem is that my app crashes when garbage collection is disabled. And in the Xcode debugger console (when garbage collection is enabled), right when my app starts I get these errors:

    Code:
    MyApp(9874,0xb0103000) malloc: free_garbage: garbage ptr = 0x101bfb0, has non-zero refcount = 1
    MyApp(9874,0xb0103000) malloc: free_garbage: garbage ptr = 0x101ec90, has non-zero refcount = 1
    MyApp(9874,0xb0103000) malloc: free_garbage: garbage ptr = 0x1021560, has non-zero refcount = 1
    MyApp(9874,0xb0103000) malloc: free_garbage: garbage ptr = 0x1027da0, has non-zero refcount = 1
    MyApp(9874,0xb0103000) malloc: free_garbage: garbage ptr = 0x10293f0, has non-zero refcount = 1
    MyApp(9874,0xb0103000) malloc: free_garbage: garbage ptr = 0x102a2a0, has non-zero refcount = 1
    MyApp(9874,0xb0103000) malloc: free_garbage: garbage ptr = 0x102cd00, has non-zero refcount = 1
    MyApp(9874,0xb0103000) malloc: free_garbage: garbage ptr = 0x1030e70, has non-zero refcount = 1
    MyApp(9874,0xb0103000) malloc: free_garbage: garbage ptr = 0x1032bf0, has non-zero refcount = 1
    MyApp(9874,0xb0103000) malloc: free_garbage: garbage ptr = 0x1033430, has non-zero refcount = 1
    Any help with this would be appreciated. Source code is available upon request

    Thanks
     
  2. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #2
    If you get these errors in immediately upon launch, you should check all your init and awakefromnib methods. Somewhere should be a forgotten retain or release. But without code, it is difficult to help you.
     
  3. scootaru macrumors 6502

    Joined:
    Nov 7, 2008
    Location:
    Columbus, OH
    #3
    I thought all of the retains and releases were ignored if garbage collection was enabled. I'm very new to this, but that's what I thought.

    OP, after an object is no longer needed, do you assign it to nil? Again, I'm new, so I'm not sure if it will make a difference, just an idea.
     
  4. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #4
    Probably, I don't use GC.

    I never do.

    Again, if you want help with finding a bug, post some code.
     
  5. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #5
    It would make a big difference to garbage collection. As long as there are ways to reach an object, even if you are never going to actually use it, it will not be garbage collected. If you don't use garbage collection, then setting pointers to nil is a good way to avoid using them again, or releasing them too often.
     

Share This Page