I just switched my app over to ARC. The transition was a partial success thanks to the refactoring tool that Xcode provides. The one part that doesn't work is a strange error.
I used method swizzling (method_exchangeImplementations) so that instead of calling UIView's initWithFrame, it will call my myInitWithFrame code. The refactoring process threw an error at the method declaration of myInitWithFrame, so I added the __attribute__((objc_method_family(init))) after the declaration of the method. Now this all works perfectly fine for iOS 6.0 and above, but on iOS 5.0 (the lowest iOS I would like to support) it doesn't work. I'm getting an EXC_BAD_ACCESS (code=1, address=0X28). On every run the exact same memory address comes up.
I have a UIWebView that calls it's:
[[UIWebView alloc] initWithFrame:webViewFrame];
After the myInitWithFrame does it's initialization, it returns self, then it crashes.
On the thread trace, it says that it crashes in apples's code (the method is greyed out) on the [UIWebView retain] method, as seen below.
Thread 1, Queue : com.apple.main-thread
#0 0x3515a7d2 in -[UIWebView retain] ()
#1 0x316ddef4 in objc_retain ()
#2 0x0011528c in -[UIView(style) myInitWithFrame:]
Sorry that the thread trace isn't very well formatted, I don't have enough rep to post an image.
Is there any reason why the same code works for iOS 6.0, but not iOS 5.0?
This issue was very complicated to fix. The fact that this issue only showed up on iOS 5, and not iOS 6 was my first indication that this may be an apple issue, or an method swizzling issue. After about a week of searching I came to the consensus that I should email Apple technical support, to see if they could help me with this issue.
Their response was that it's both our faults. He said that in iOS 5 UIWebView keeps track of it's own retain count (using a UIWebViewInternal class), and that my method swizzling was retaining the object before it was fully initialized, and that caused the crash. When I didn't use ARC it wasn't an issue, because I never call retain in the init function, but with ARC it adds retains as it "sees" fit. He mentioned that in iOS 6 the UIWebViews don't manage their own retain count, and that's why it worked in iOS 6.
Related
I'm developing an application that uses the Apple SpriteKit and CoreImage framework. On iOS 10 the application starts and is fluid, but on iOS 11 the application stops and after using the profiling tool "Zombies" I get the message
[MTLDebugTexture release]: message sent to a deallocated instance
(more precisely, it is an instance of AGXMetalA8X that is accessed by jet:: create_texture () but which has been deallocated before by CoreImage... All of those classes belong to frameworks, not to my app)
I've tried many solutions proposed in response to this type of error, but the problem doesn't seem to be directly related to my code.
By adding the option "PrefersOpenGL = YES" in the Info.plist file there is no more this error. However, the graphics rendering is very bad with this option enabled.
I also tried to keep strong references to all the SKNode elements I create and to reduce memory consumption but this only delays the error. Moreover, it is not a very memory-intensive application (about 40MB of RAM consumed, on average, no apparent leak)
XCode 9 , Swift 3.2 , SDK iOS 11
Fun error that ONLY happens in iOS 10, when debugging on a physical device. It does not happen in the simulator, or when running on the physical device (while not debugging). It also does not happen on an iOS 9 device in any situation...only iOS 10 while debugging and after any javascript call has been executed.
I have a hybrid web app, written in Swift 2.3, after the xwebview loads I call various javascript methods...actually, any in this case. Anyway, after the javascript method has finished I get a malloc error saying I'm trying to free a pointer.
malloc: *** error for object 0x1740b5060: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
So I set the break point...and it never breaks on the breakpoint, it just keeps telling me to set a breakpoint.
If I remove all of my javascript calls, the error never happens. I've tried enabling them one by one, it doesn't matter, they all break after the callback returns.
I've been after this for about 2 weeks, I'm out of extra hair to pull out. At this point I'd love to hear if someone else is seeing the same thing.
It looks like its a safari bug and therefore only appears when you are debugging your webview with safari. In Safari under Develop->Your_Device_Name uncheck "Automatically Show Web Inspector for JSContexts".
This should resolve your issue.
I have built an App in Swift but with Cordova which is Obj C. I also use crashlytics. I'm seeing a crash in about 10% of users, previously I experienced it a lot myself when using the debugger but since iOS 8.3 I don't, but that doesn't seem to have reduced the problem in the wild.
The crash is EXC_BAD_ACCESS KERN_INVALID_ADDRESS in CA::release_objects(X::List<void const*>*) + 32, called when the autorelease pool is drained. The crash is always in the WebThread.
I can't seem to reproduce locally with Zombies profiling, so it is difficult to narrow down any further, but I can't see what would be causing this in my code. I do use Core Animation but only in swift, and this was happening before I added the CA code. I use UIView animations, but again it is all in Swift with Storyboards and I can't think where anything would be going wrong. Any suggestions?
I spent few days working on an app that was built by my friend last year before the release of iOS 8 and Xcode 6+ I believe. He used several libraries like PMCalender , FXforms, MyBlurIntroductionView, CCPickerView, SWRevealTableView etc and I added MBProgressHUD. Now before the app was running without crashes or now as I understand after further studying of the problems I am getting with the app. I believe the app has multiple because of memory leaks. I read his code before modifying it and just noticed there are compile sources he put i.e -fno-objc-arc or fobjc-arc. About a day ago after attempting to integrate SPGooglePlaceAutocomplete for some reason I had to disable Objective-C ARC from Build Settings and then the whole project build with lots of errors. That I had to change weak object to strong in some header file and so forth.
Now I tried to read this for more understanding Apple Transitioning to ARC release NOte
I am posting this question because I'm would say I'm a newbie to iOS development but catching up pretty fast. I need help to have a smooth running app with crashes because. What I am experiencing is not clear to the point that I had to use Instruments to see exactly what is causing the app to crash whereas coming into the app several time at some point it does not crash. When it crashes I get this only thread x and can't really know where to debug
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
The add has MapKit and first thing after login screen it should zoom to the user current location. Reason why I used Instruments to see what is happening with the app is because I was suspecting perhaps CoreLocation is causing the crash to connect to the remote CCLocationManager services. As I noticed my phone takes time to turn on gps and it does not always stay on even if I have request location always [self.locationManager requestAlwaysAuthorization];
So I am hoping someone can help me because I did the whole ARC transitioning but still have release, autorelease errors. All my IUOutlet are weak.
Here are the 6 errors I am left with removing with hoping the app will run normal.
I this this is the answer to my question, which can be helpful to others after long search and debugging.
http://www.daveoncode.com/2011/10/24/migration-to-arc-automatic-reference-counting-using-xcode-4-2-refactor/
I have being seeing crashes in my iOS app, when opening LA Times (www.latimes.com). The crash happens in WebCore somewhere and I have no clue where. Profiling with both "Zombie" or "leaks" do not return anything for this "EXE_BAD_ADDRESS" error.
I also checked with a small, bare UIWebView app and I could reproduce the effects.
Right now, I see this happening only with LA times, but I am not sure if there are other sites as well.
Can someone check on and guide me in what could be the possible error/source for this crash?
EDIT: I have added a small UIWebView project demonstrating this bug at
github
EDIT 2: The app (include the demo at github) works perfectly fine on iOS 7.0, but crashes in iOS 7.1 ... seems a recent bug with iOS 7.1. I have issued a bug report to Apple and will keep updated.
Thanks in advance,
Nikhil
I happened to bump into that same issue with one of my apps in iOS>7.0 only.
It seems to be a sync issue which can be fixed by creating the webview from the main thread only.
As a fix I just wrapped my UIWebView creation in a dispatch_sync(dispatch_get_main_queue(), ^{ ... });
And it solved the problem.
Of course if your code is running on the main thread you shouldn't wrap it this way ;)