New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memory leaks with garbage collection #45
Comments
I don't have any experience with GC - does this mean these will actually leak, or do you think Clang is just confused? I guess in some cases I could switch to using CFRelease(), but I prefer to use autorelease. Lots of methods return early, so it's easier to ensure I'm not forgetting to release something. |
I don't have any experience with CoreFoundation, but it looks like this actually does cause memory leaks. (I'm thinking now that those reports by my app's users that it leaks like hell might have something to do with this... though I haven't investigated this at all so I'm just guessing here :) There's a page in Apple's documentation that explains in detail how to use CoreFoundation with garbage collection: http://developer.apple.com/mac/library/documentation/cocoa/conceptual/GarbageCollection/Articles/gcCoreFoundation.html It seems the solution is to call CFMakeCollectable or NSMakeCollectable on the CoreFoundation objects - if I understand correctly, in GC mode this lowers the reference count for CF objects to zero (making the object collectable when it goes out of scope, not releasing it immediately), and in non-GC mode it does nothing, so it's safe to use it even without GC. If I wrap a call to e.g. CFReadStreamCopyProperty in CFMakeCollectable, Clang stops complaining. The leak is apparently caused by the fact that CF* creation methods increase the reference count even in GC mode, but Cocoa's [release] and [autorelease] are no-ops in GC mode so they don't lower it and it stays above 0. |
I've looked at the memory allocation in my app and I'd say that probably the problem is somewhere within the UI (mainly with images), not with the http requests... but it would be nice to fix this anyway. |
Many thanks for the info! :) I've wrapped all the calls the static analyser complains about in NSMakeCollectable, and added CFMakeCollectable calls in markAsFinished to free up the CF objects a request hangs on to (as dealloc won't be called). I've done a quick run with the leaks instrument, and it looks like the leaks should be gone, but please let me know if you're still seeing them! Thanks again Ben |
Looks good, no more warnings, thanks :) |
Guys, does this issue fixes problems for iOS or it is Mac only? |
Definitely Mac only, this is only relevant to garbage collection and there's no garbage collection on iOS for now. |
If I run 'build and analyze' on a garbage-collection-enabled project using ASIHTTPRequest, I get 10 warnings with the message "Potential leak (when using garbage collection) of an object..." (in ASIFormDataRequest.m and ASIHTTPRequest.m). Could you look into this? (It seems it's mostly related to objects allocated using CoreFoundation functions and deallocated using autorelease.)
The text was updated successfully, but these errors were encountered: