Memory leak with UIWebView - memory

My project is a hybrid static lib for showing a UIWebView with some JS to control the logic. When I use 64bit and run demo on iOS 8/iPhone 6, the memory keeps going to 30M or more!
When I use generation in instrument, the increased memory usage is almost all from webcore; does it means there are leaks in JS code? I can't find a leak when I use Safari to run similar JS directly.
When I release the UIWebView, the memory is still not freed; I tested with instrument allocation. There are some webcore and (non - object) still in memory, what can I do to release them?
0JavaScriptCore WTF::MallocHook::recordAllocation(void*, unsigned long)
1 JavaScriptCore WTF::fastMalloc(unsigned long)
2 WebCore WebCore::SharedBuffer::buffer() const
3 WebCore WebCore::SharedBuffer::data() const
4 WebCore WebCore::ResourceLoader::didReceiveDataOrBuffer(char const*, unsigned int, WTF::PassRefPtr, long long, WebCore::DataPayloadType)
5 WebCore WebCore::SubresourceLoader::didReceiveDataOrBuffer(char const*, int, WTF::PassRefPtr, long long, WebCore::DataPayloadType)
6 WebCore WebCore::SubresourceLoader::didReceiveBuffer(WTF::PassRefPtr, long long, WebCore::DataPayloadType)
7 WebCore WebCore::ResourceLoader::didReceiveBuffer(WebCore::ResourceHandle*, WTF::PassRefPtr, int)
8 WebCore WebCore::SynchronousResourceHandleCFURLConnectionDelegate::didReceiveDataArray(__CFArray const*)
I use the following code.
-(void)createUIWebview{
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:serviceUrl]]];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:#"WebKitCacheModelPreferenceKey"];
}
-(void)dealloc{
if (_webView.isLoading){
[_webView stopLoading];
}
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"about:blank"]]];
_webView.delegate=nil;
[_webView removeFromSuperview];
[_webView release];
_webView = nil;
}
I have researched the following links, but they don't seem to solve my problem.
Is UIWebview still leaking in iOS 8? And the problem seems not so obvious when I use iOS 6 in iPhone4.
Whats the proper way to release a UIWebView?
iOS 8 UIWebView memory management
UIWebView leaks, JS Garbage Collector & WebCore VMs
Release memory/cookie/cache from UIWebView once closed

I was having the same problem and switched to the new WKWebView and it immediately solved all of the memory leak issues I was seeing. WKWebView shares many of the same call names from UIWebView so all I had to do on my project is switch over all my `UIWebView' objects to 'WKWebView' and the memory leaks went away.
Remember to import the WebKit into your project and know that is is only available on iOS8.
Apple Documentation

I had a similar problem, having users testing the app by previewing images in UIWebView. The app would crash after N previews. Using Apple Instruments tool with Allocations profiling template. From the tool, I was able to select the following Allocation Lifespan: "Created & Persistent". Further observations is when previewing the same file multiple times, Persistent Bytes (Based on apple definition, this is the number of bytes that have been allocated, but not released.) for ImageIO_jpeg_Data keep growing in doubles, this is true for any other image type.
A resolution for this is to use UIImageView from apple as a separate previewer for Images, this cause no memory leaks at all when previewing images.

Related

Memory Leaks in NSBundle iOS 13

I have a memory leak in my iOS app, some of the leaks were due to my code written which i was able to fix. But this i was unable to know what the issue was. Any one who can help me with this.
This is the screenshot for reference:

WebCore bmalloc::IsoAllocator crashes in iOS 11.3

I am getting crash like this in fabric crashlytics:
WebCore
bmalloc::IsoAllocator >::allocateSlow(bool)
Any clue to resolve this issue?
i'm getting same crash.
in my case, when large html load on webview and inline css in the html was reason.
check your html content.
this is knowledge in my case. not a question.
more detail is
i'm using UIWebView.
my same crash was to occur when client updated on ios 11.3
i checked all webview.
when call loadrequest on uiwebview function.
crash occured when large html load. the html content size was
char length 80000 ~ 200000. it's breaking on css in html content.
this is my case. I hope it helps.
In my case it helped to set the webView.delegate to nil after I used the webView.

Why would this app crash 100% when running from Testflight, maybe 10% from Xcode

EDIT: I am going to repost a different version of this - I think I was focusing too hard on the fact it crashes in Testflight and not on the fact it crashes on iPhone but not iPad. (even from TF)
I'm having an annoying problem, and previous similar answers on SO aren't helping much.
I have a game (using Sprite Kit) which sometimes crash when a certain method finishes running. It does this 10% (or less) of the time when I run it on my iPhone 5s from Xcode, but if I upload to Testflight, it does it 100% of the time.
Xcode doesn't give me great debugging info, it shows a green breakpoint line in main.m on this line:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
and on the left panel it says this happens in:
Thread 1:
Queue: com.apple.spritekit.renderQueue 0
SKCRenderer::preprocessSpriteImp(std::__1::vector >&,
SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float,
unsigned int&, bool)const
and I see an EXC_BAD_ACCESS (code=EXC_I386_GPFLT) in this line:
0x1015bc663: movq 16(%rbx), %rcx
I will attach a pic actually of the surrounding stuff
I am bad at debugging and I don't know what to do. One notable thing is that this never happens in the iPad version. I'm very confused as to why it would happen sometimes but not always.
Because of derived data app might not crash while running from xcode. Few bad access are hidden if zombies are enabled.Its all about memory reference and some thing which legally is dead but actually exists at memory location can hide a legitimate bad access.
Try deleting derived data and disable zombies you will get same bad access from xcode as well.

UIWebView webCore crashes in iOS7.1 (example: www.latimes.com)

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 ;)

Flurry Analytics - NSAutoreleasePool allocWithZone:] - memory leak after upgrading to Objective-C ARC

I just recently upgraded my project to iOS 5 with ARC (automatic reference counting) and now Instruments is reporting a memory leak from NSAutoreleasePool after I suspend the app in the background.
I suspect the leak is being caused by Flurry Analytics based on the stack trace with these two API calls:
+[FlurrySession sendSessionsToServerForSessionPause]
+[FlurrySession sendSessionsToServerWithTimeout:useWebView:requestAppCircleAds:requestVideoAds:requestAppSpotAds:sendCurrentSession:]
I'm not making any Flurry API calls on suspend. The only call being made to flurry is
[FlurryAnalytics startSession:<my id>];
when the app first starts.
Reported leak
Leaked Object # Address Size Responsible Library Responsible Frame
NSAutoreleasePool,1 0x7693f600 32 Bytes Foundation +[NSAutoreleasePool allocWithZone:]
Stack trace
10 libsystem_c.dylib thread_start
9 libsystem_c.dylib _pthread_start
8 Foundation __NSThread__main__
7 Foundation -[NSThread main]
6 iSURVEY +[FlurrySession sendSessionsToServerForSessionPause] /Developer/Applications/iPhoneAdAgent_modular/Classes/FlurrySession.m:931
5 iSURVEY +[FlurrySession sendSessionsToServerWithTimeout:useWebView:requestAppCircleAds:requestVideoAds:requestAppSpotAds:sendCurrentSession:] /Developer/Applications/iPhoneAdAgent_modular/Classes/FlurrySession.m:962
4 CoreFoundation +[NSObject(NSObject) alloc]
3 Foundation +[NSAutoreleasePool allocWithZone:]
2 CoreFoundation +[NSObject(NSObject) allocWithZone:]
1 libobjc.A.dylib class_createInstance
0 libsystem_c.dylib calloc
Edit:
I just tried turning off all debug variables like zombies and the memory leak is still exactly the same.
Edit 2:
Okay I've confirmed that it definitely is a Flurry issue. After removing the call
[FlurryAnalytics startSession:<my id>];
I no longer get the memory leak.
I'll file a bug with the Flurry team.
I see the same 32 byte leak. I was thinking about releasing it that way, and watching for an update. A one time 32 byte leak doesn't seem like it's a big problem. I only see it when the App registers with Flurry, not every time the task comes out of the background. I'm using Flurry version 3.0.2 with iOS 5.0 as the base SDK, and a target of iOS 4.1
Looking at the Flurry docs, it looks like you can set it up to only report on application launch.
Before your
[FlurryAnalytics startSession:id];
Add the following two calls:
[FlurryAnalytics setSessionReportsOnCloseEnabled:NO];
[FlurryAnalytics setSessionReportsOnPauseEnabled:NO];
The docs say that "OnPause" is off by default, but it can't hurt to be sure.
I also filed a bug report with Flurry.

Resources