Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pcwiz

macrumors member
Original poster
May 28, 2008
55
0
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
 
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

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.
 
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.

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.
 
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.

Probably, I don't use GC.

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.
I never do.

Again, if you want help with finding a bug, post some code.
 
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.