I am creating a static framework and will be using it across multiple applications. In the framework code I have disable ARC flag and is set to NO.
Other projects where I will use the framework may have ARC set to YES or NO. So if there is mismatch in ARC flags in Framework and the project where the framework is used, the application crashes since it tries to deallocate something which is already de-allocated.
Is there a solution to the above issue?
Regards,
Nirav
ARC is a compile time setting, so it is per-file not per-application. All you have to do is make sure your code in each file agrees with the compiler about if it's using ARC. If you want to throw an error if a file isn't using ARC when it should be, use something like:
#if !__has_feature(objc_arc)
#error This file should be compiled with ARC enabled
#endif
and similarly for detecting the opposite.
Related
I am maintaining a static iOS library i inherited from a former coworker using Xcode and Objective-C. The code contains a lot of
#if __has_feature(objc_arc)
and i was wondering if i can just assume that arc is always available? The library gets distributed to customers so another question would be: Do they maybe have to change something to use my library after i "forced" it to use arc? I already tried to find something about it and so far it seems to me that you can use arc frameworks in non-arc projects. But i'm not completely sure if i got that right and also i don't want any customer to do extra work because of that.
If you're distributing it in compiled form, then yes, it either has ARC on or it doesn't, and that's completely under your control. The user of the binary can't change it afterwards; ARC "happens" at compile-time.
If you're distributing it as source, you could document the requirement for ARC, and issue a compilation error if it's lacking by putting a similar guard in just one place:
#if !__has_feature(objc_arc)
#error "MyLibrary requires compilation with ARC"
#endif
and remove all the others scattered around.
Finally, code that's compiled with ARC can be freely linked with non-ARC code. The only problem arises if the MRR code does not do proper memory management, but I would classify that as an exposition of an existing bug in that code rather than a problem caused by using ARC.
I am developing an IOS application. I don't use ARC, my project is non ARC project. Bu I'm using a library developed for the ARC. This librar is AFImagePager. This librar is image gallery. So I added a flag What is -fobjc-arc at required file. But when running the application gives memory error. Memory usage is constantly increasing, not decreasing at all. Is this normal
You don't have to enable ARC for your project, using ARC isn't just a matter of adding -fobjc-arc, it's more involved than that.
The only thing that you can't do if you use a library that is ARC, is use GC, because that's not compatible.
If your project was MRR and working fine, continue to do so.
For your application, make sure you are doing proper memory management. That is the only thing that I can think of that might be causing those errors. Tip: go to Product -> Analyze… and check on all the memory issues it reports.
I have a project previously built in iOS 4.3. When I tried to invoke the “ARC” conversion tool with
Edit > Refactor > Convert to Objective-C ARC
from XCode 4.5.2, the tool reports many errors. Some are supposed to be modified automatically by itself, for example the keywords autorelease/release/retain should not be used.
The errors seem too many (1,987 occurrences) to resolve by hand. Are there any configuration options that i am missing or should something else be done?
If you are using existing libraries you can simply not use ARC for those libraries and begin using it throughout your app by using a flag.
Add this to your library or files in question to ignore ARC
-fno-objc-arc
i think you have used any third party libraries, if you have used any third party libraries then it won't helps you.that means in this situation it wont automatically converts it to ARC.
Unfortunately ARC manages memory only for objective-c objects, if you have used any C or C++ files then in this case you have to handle memory management yourself
I just cloned the git repository for the SBJson framework and imported the source code into my application. Ran a Static Memory profiler and got a little scared from the results I saw.
See the picture
How is this possible? I doubt the developer of this very well known library didn't see this? And indeed, if a run a memory profile it shows memory leaks from this library.
Any ideas?
Thx
It looks like you're using SBJSON in a project that doesn't have ARC enabled. Since ARC removes the need to call release explicitly, code written for ARC (like SBJSON) causes memory leaks when used in a non-ARC project. You should convert your project to use ARC with the built-in refactoring tool (Edit > Refactor > Convert to Objective-C ARC, then explicitly set the -fno-objc-arc compiler flag on any of your source that is not yet ARC-ready.
I'm trying to compile an old project that I changed the UI a bit, but I've updated to Phonegap 1.0 and Xcode 4, so I'm getting this errors:
What should I do?
It looks like you now have ARC (Automatic Reference Counting) set on in the project. To use ARC your code will have to change, one of the changes is the way the autoreleasepool is created/drained.
Other things that are not available are retain. release and autorelease, the compiler generates all of these behind the scenes as necessary. This all works iff all of the Obj-C naming conventions have been followed.
Xcode has refactoring help to convert a project. However this many not be appropriate in your case, if that is true turn it off in the project/target build settings:
ARC can be disabled on a file-by-file basis:
There is no problem mixing ARC compatible files with non-ARC files. This can help bring legacy projects to ARC. ARC is the future.