Question

I added PESGraph arc library to a project without arc.

I have already found an answer that it is possible and it really works. But how to handle memory for objects from arc library in non-arc project. I mean at least alloc, retain, release.

For example can I write release in dealloc method for object from arc if it was declared as retain property?

Was it helpful?

Solution

If a file is compiled with ARC disabled, you can call release (and retain and autorelease) in that file, and you are responsible for making those calls in the proper places.

The idea of ARC is that, when ARC is enabled, the compiler inserts those calls for you. If you have ARC disabled for some of your files, then in those files you must insert the calls yourself.

Cocoa has very strong conventions for when you need to retain, release, and autorelease objects if ARC is disabled. Read Cocoa Core Competencies: Memory Management to get started. Then look at the Advanced Memory Management Programming Guide if you need more details. It's not really very advanced.

The compiler follows the same conventions when ARC is enabled. That is why you can link ARC-enabled files and ARC-disabled files in the same executable.

OTHER TIPS

Memory management in Cocoa is completely local -- what memory management operations need to be performed in a function can be determined purely by looking at that function only, without caring about other code. Each function can be considered independently in terms of memory management, as long as they all follow the rules. ARC simply implements the rules (the same ones you would follow in MRC) automatically. Different parts of the code can use ARC or MRC independently, without affecting each other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top