Tried to convert an iOS app using AdWhirl to ARC (Automatic Reference Counting).
There are several autorelease calls within AdWhirlView.m that ARC forbids.
When I refactored all my paid apps (that didn't have adwhirl) to ARC, XCode just removed my retains, releases, and autoreleases for me, but something about the way the code in AdWhirlView.m is written has caused XCode to pause, noting "[rewriter] it is not safe to remove an unused 'autorelease' message; its receiver may be destroyed immediately."
Is anybody able to rewrite AdWhirlView.m to work correctly with ARC?
Or will I be forced to avoid combining the two? =/
Thanks in advance!
Alright, I've found the way around this...
When you click "Convert to Objective-C ARC" it brings up a menu called "Select Targets to Convert"
All you have to do is expand the list of files by clicking on the drop-down arrow, then deselect all the AdWhirl files.
XCode will convert the rest of your project to ARC without hitting on an error when it gets to the AdWhirl files.
Related
I'm making my first app and it's really confusing.
I am using ARC, and probably ALL of my potential leaks say:
"Object leaked: object allocated and stored in 'point' is not referenced later in this execution path and has a retain count of +1"
They are on almost any object I create using [[alloc] init].
Any suggestions about how to handle those? The app works fine, though.
Thanks.
Are you sure your project is actually set to ARC? Those types of analyzer warnings sound like it isn't. Is this a new project where ARC was automatically turned on for you or did you do the conversion for it yourself?
There isn't a way to actually tell the analyzer that you are ARC or aren't. It will just pick that up from the settings automatically.
I have two Levels level1.mm and level2.mm
In Level1.mm i use button named "skip level" MenuItem to Replacescene to go to level2.mm ,But when that method gets called, my app crashes with exec bad access.
But if i use PushScene its going to level2 scenes properly.But I know somewhere memory will be waste if i use pushscene.
What is the bestway to replace scene?should i call any dealloc before replacescene or it will be called automatically?
note : Please Be gentle this is my first game in iphone :) :)
The fact that replaceScene crashes but pushScene does not tells me that the first scene has some kind of issue when it is being deallocated. So your question isn't about how to replace scenes, but rather how to find and fix the bug that causes the crash.
Try this tutorial to learn more about debugging with Xcode. And since you're new, you probably aren't using ARC yet. Do that now because it'll help to avoid a ton of similar issues.
While developing apps in Xcode memory leaks are occurring. When I checked them in extended detail view they are showing different methods that are not related to implemented. How to exactly find out which object is leaking and where it is leaking memory.
When ARC is enabled we have to take care of memory leaks or not?
Even with ARC memory leaks can occur, it just inserts release and autorelease during compile time.
1. You must check for leaks using Build and analyze in XCode, shift+command+b you should be clearing those issues.
2. After that you can start using the instruments by using profile option command+i . This will point you to where the leak might be.
This link will help you too http://soulwithmobiletechnology.blogspot.in/2011/04/how-to-check-memory-leaks-in-xcode-4.html
Edit: Added some screenshots to hopefully make it clear.
During profiling after selecting leaks choose the call tree option and check the boxes hide system libraries , invert call tree and show obj-c only as shown in image below.
After double clicking the symbol name below you'll get the line where it is leaking.
You'll get something like this.
Yes, even with ARC there are memory leaks. ARC is not a garbage collector, it only inserts for you, at compile time, retains, releases and autoreleases in key positions. So although it does help the developer, you should be aware that memory leaks still exist (for instance circular referencing). You can start by using the Static Analyzer and correct any problem it shows you. You can then go to Instruments and choose Leaks.
I have Xcode 4.3.1, iOS 5.1, and have ARC turned on for building my app.
Now the app runs fine in debug build, but crash on release build. What could be the possible reason for the difference? I purely rely on ARC for the resource management. I looked at the crash log, it's indicating that the memory that was referencing was released already. What'll be the common pitfalls that could cause the problem on retail build, when using ARC?
The following is what I got from crash log
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x6f636552
Crashed Thread: 0
EDIT
The app's deployment target is iOS 5.0. I do use internet connections, the current crash happens on the time when "rendering" the data returned from web service in order to show on a UITableViewController. The whole app is using ARC, except a few source files from 3rd party for which I have ARC turned off.
Whenever this happens to me it seems to be because release builds are more aggressive about clearing up weak references. If you mistakenly assign something to a weak property (for example, if you're adding subviews that you will also hold weak references to) before you have any strong reference to it, this can work on debug and fail on release. For example (pseudocode)
#property (weak) UILabel * label;
...
self.label = [[UILabel alloc] init];
[self.view addSubview:self.label];
...
self.label.text = #"hello";
I've seen this cause bad access crashes on release builds and go unnoticed on debug.
I may not have the answer but I'm going to list a few hunches for you to try:
Make sure you are not passing objects into methods without a "handle" on it on your side. And example would be passing a handler class instance to a method that expects a delegate. The method doesn't retain that instance and so it gets released before it even calls the method.
Check your pre-compiler macros that they are safe for both DEBUG & RELEASE builds. A good example is having an if statement over a macro that is removed in release builds and the if statement doesn't cover it with curly braces.
If you depend on compiler definitions to enable/disable certain parts of your code (through the use of #if conditions) make sure the needed ones are set in your build configuration.
If I can think of more, I'll try to add them.
Do you have a different target for release and debug? Check whether all the files are correctly referenced for the release target.
In our case, a category on UIButton was not seen by the release target. An ad-Hoc build went just fine, until someone invoked a method implemented by that category. Since we did not store an archive from the Ad-Hoc build, there was no way to debug a crash. (lesson learned)
Not sure whether it is listed as EXC_BAD_ACCESS in a crash log, but could help someone to identify their release-specific crash.
I have some code that returns a struct containing 2 objects (declared as id).
When trying to use one of the objects I get an EXC_BAD_ACCESS and the app crashes. This only happens on the device (ipad) not in the simulator.
I have set NSZombieEnabled to YES, however no information is written to the console.
I don't know if it's a problem that I'm using a workspace in Xcode 4, one project for my app, and another that builds a library which is used in my app. The EXC_BAD_ACCESS is occurring in the second project, so I don't know if NSZombieEnabled will apply to the second project?
How do I solve this? Especially as I it only happens on the device (even goes as planned on the simulator), and it is in the second project?
EDIT: This is the method where the EXC_BAD_ACCESS occurs, on line 62, on sortRange.lower –
NSZombieEnabled only works on the simulator, not on the device, so it's probably hiding the problem. Run Product > Analyze (⇧⌘B) for clues. It's harder to say more without looking at the code. As Mihai says, your objects are probably over released, which is the most common cause of EXC_BAD_ACCESS.
It seems that one of your objects is autoreleased before you are trying to access it. As the iPad has less memory than the computer you are running it on it get's released faster so that's why it's not available. Try NSLog both objects just before the line you are getting the error and see wich one of them is the problem and than trace back to it's origin and retain it somehow. Also don't forget to release it after you are done using it. Some example code would be useful.