Reputation: 3805
Can anyone tell me, the correct usage of Enabling garbage collection, basically i am not able to understand following,
1 -- I am working on a Third party application, which has got garbage collection enabled, 2 -- Just for experimenting i disabled Garbage collector and compiled with "Unsupported" garbage collector, 3 -- i builds the application, but when i try to run the same , it faulted and giving
Program received signal: “EXC_BAD_ACCESS”
Might be some problem in the application only, and preventing by using garbage collection, so i want to know, Is it a good practice to continue with the Garbage collector , or disable it and try to fix all such kind of faults.
also, using garbage collection will cause any extra memory over-run ?
Upvotes: 0
Views: 647
Reputation: 96333
Can anyone tell me, the correct usage of Enabling garbage collection, basically i am not able to understand following,
1 -- I am working on a Third party application, which has got garbage collection enabled, 2 -- Just for experimenting i disabled Garbage collector and compiled with "Unsupported" garbage collector, 3 -- i builds the application, but when i try to run the same , it faulted and giving
Program received signal: “EXC_BAD_ACCESS”
Well, wait. Are you trying to enable it or disable it? First you say you want to know about enabling it, but then your list of steps says that it already was enabled and you disabled it.
Garbage-collected code and reference-counted code are different. You can't take code that was written to expect GC, compile it under reference-counting, and expect it to work. If it even compiles, a crash is indeed the most likely result. (Code going the other way will not compile.)
You could try converting to ARC, which will have fewer differences than the old manual reference-counting. However, GC code compiled with the GC is still perfectly valid, at least for now; the “faults” that you see when you run GC code without GC aren't faults when GC is enabled.
So, it's probably best to just leave GC enabled, at least until you're more familiar with both that code and the language.
Upvotes: 2
Reputation: 14694
If the project is already in a Garbage collected environment then you should keep using it - unless you really want to go through all of the code and manage the memory. In the end though what would the benefit be? There can be speed improvements moving away from GC, but for most apps they will be not be noticed, and depending on the size of the project it could take a very long time to get it running correctly. You'll also greatly increase the chance to introduce errors.
If the app is Lion only you might consider moving from GC to ARC, although that would require time to integrate as well.
If you haven't already I suggest reading Apple's Garbage Collection Programming Guide.
Upvotes: 1