I'm creating an app based on storyboard, where each of the views has quite a lot of large images. The app crashes (not a lot, it usually crashes after 10-15 minutes of intensive use) after having displayed a few memory warning.
I've checked instruments, and it's not reporting any single memory leak. Also, the allocation seems to be reasonable (I've only got 1 or 2 peaks in the game when I load some very xib containing very big images - around 8mo for the iPad retina version).
I don't really have any objects I can release when I receive a memory warning, as all the stuff from the previous view has already been deallocated.
I've seen that similar problem, but it seems to be related to a specific line of code, which is not my case : iOS - App crashing after Memory Warning - Instruments showing no leaks
Is there a way to force xcode to clean the images that are cached?
Otherwise, what can I do to prevent these crashes?
Thanks for your help !
I have had the similar problem, but my solution was at the end easy:
You should think the Iphone is like a car. A car can't speed up to 100 Mph in one second. A Iphone can't load big images in one second. So what you have to do is: you should shrink the size of the images and if there are more than 2 big images on one view just delete one of them or put it to other views.
If that is not your solution look for mistakes in the code and check up, where the app crashes.
Related
I have a problem with using UIWebViews in an objective-C app we're developing. It crashes any Retina iPad. Both iPad 1 and 2 behave fine.
The web view is loaded from local HTML/CSS/JS and is dynamic content that contains pricing information so needs to be essentially a mirror of a website which is pre-downloaded to the device.
The page contains lots of images so I think this is memory related. I've tried reducing the payload on the page which stops the crashes. Obviously the stupidity of Apple to choose to quadruple resolution whilst only doubling memory is a root cause of why it works fine on non-retina devices, but how can I manage memory within the page to prevent iOS from destroying the entire app?
Does iOS automatically store imagery as 2048x1536x32bpp as a bitmap (theoretically 12MB per image?) irrespective of the file format? I've tried converting to JPG / PNG but with no effect on the crashes. Only reducing the volume of images present on the page stops the crashes. It's my first foray into iOS development, so please be gentle!
iOS won't change the resolution of the original images that the page loads, but of course it will de-serialize them from .png/.jpg to a bitmap in memory for display, so you should start by trying to reduce the resolution of the .png/.jpg images that the page loads.
I'm having memory issues with one of my apps and I've identified "Real memory" as defined in Instruments> Activity monitor as a possible culprit.
My app allocates large UIImages within UIScrollViews. There's a CIImageFilter applied to one of the images. Activity monitor shows that upon the first pushing of the view controller containing scrollviews with large images, the real memory use jumps to around 300mb. Subsequent pushes/pops raise it to about 500mb:
I read that "Live Bytes" does not count memory used by textures and CALayers, so my question is: How do I properly release memory that is used by CALayers of my Image/Scrollviews?
See the real memory usage blue pie chart on the right:
Both real and virtual memory are the highest for this process:
What bothers me is that I'm trying to clean up my large scrollviews and images when popping that controller, and the numbers for the "Live bytes" go down to about 5mb, while "Real Memory" stays outrageously high(~500 mb):
ContainerScrollView* container = ...;
[container.view removeFromSuperview];
container.view = nil;
Here's the allocations profiling:
I found a person experiencing a similar issue here:
Mysterious CoreImage memory leak using ARC
The answer (I really hope it is) appears to start using NSData dataWithContentsOfFile: and then create a UIImage imageWithData:. Got an image a user picked? Write it to a temporary file and read it back. I do not trust any other image methods, as they, in my 12 hours of testing appear to behave irrationally in iOS 6.1.2 for large image views.
I'm very new to objective C, that's actually my first app...
I'm working on an application which has a list of projects, each project has its own gallery of images, segues וarc. the gallery takes about 90% of the screen, and a row of thumbnail takes the rest.
It is running OK on the simulator, but when I get out of one gallery to another (somtimes after three or four passages) the application crashes (on real device - iPad2 with IOS 6).
There is no exception or error, the log is clean. It seems to crash when the application reaches 350MB of RAM.
I believe there is no memory release between passing trough the galleries, even though I am usingבarc וsegues.
In addition, on the first entry to each gallery, it takes a few seconds for the gallery to load (only on first run, if I exit and reenter the same gallery it enters immidiatly) which seems further clue that it is kept in the memory.
I would really appriciate any idea, even if it simple as this is a first app and I'm not very experienced.
Thanks for your time and help...
I am not sure the exact reason for this is the memory issue. but when you handling the big payload(data) on your project,you have to think about what happen the memory reach the maximum reachable data size allocate for the app at the time.
Thanx for the API you have a call back method when fires the app reach the maximum Data size the system can handle.
- (void)didReceiveMemoryWarning{
// in this metod you can remove(release) additional memory used by your view controller
// in your case UIImage objects of the gallery.
}
You can't call this method directly. it's a system call method.
but you have a option to ask to call method, when you debug in the simulator.
(Simulator Status Bar: -- Hardware > Simulate Memory Warning).
documentation here
I'm trying to build a weather application on the iPad but it seems that I need some help in animation. Say I'm animating a Radar, so the radar source files have 10 gif/jpeg pictures in 900x700 pixel size. I've tried the UIImage animation technique using the tutorial here:
http://www.icodeblog.com/2009/07/24/iphone-programming-tutorial-animating-a-game-sprite/
but it seems that loading 10 images that big is too much for the iPad to handle and its crashing due to memory warnings. I'm researching other techniques to animate but I can't seem to find something that will do this efficiently.
I've looked at others like Core Animation using sprites, and Cocos2D with sprites. Can someone point in the right direction the best way to animate these big images? (keep in mind that these images are dynamic and changes often so the sprites will have to be recreated on a server and fetched from the iPad to do the animation). Thanks
OpenGL only creates textures with dimensions at powers of 2. In the case of your images, that's 1024x1024, which is a meg of memory per image. Still, that shouldn't be a problem with the iPad.
First, investigate using Xcode's profiling tools to ensure the images aren't being repeatedly loaded into memory at each loop of the animation (likely by way of new objects that aren't sharing cached textures). That could solve your problem from the start.
Second, I recommend using Cocos2D if only for the easy handling of textures and caching. Toss the images into a CCAnimation, pop that into a CCRepeatForever, run it with a CCSequence. When you're done hit CCTextureCache to release unused textures.
Third, lower your animation framerate to 30 or less (if only for this animation). It may be the iPad, but you making a weather app. Not a video game.
Finally, downgrade the size of your image. Justify all you want, but a large radar animation will not sell your app. And just because a website might already be playing that animation beautifully, remember that a desktop has vastly more memory and power than any smart phone.
Try breaking the animation image into into smaller parts and animate those instead by treating each components as sprites. It would be best if you use primarily code (CoreGraphics) and draw your radar "by hand" instead of just using images as if they were animated GIFs.
Related to this question: Memory leak tool tells me zero leaks but memory footprint keeps rising
I also have a rising memory-footprint, but I don't allocate images, and more importantly, I don't do anything in the background. There's just a UIWebView on the screen, showing a JavaScript-free page. Here are two screenshots from the profiling instrument, one is 10 minutes after the other, with zero interaction and zero background activity:
(NOTE: If I set the Allocation Lifespan radio button on the left on another value, it does no difference. The live bytes have rising by about 6MB within 10 minutes.)
Now my question:
Is this an instruments-bug? Or is the WebView allocating more and more memory? Or do you think it's impossible and that I must have gotten something wrong here?
Aww sorry, there seems to have sneaked in some JavaScript that made the problem. Using a test HTML page, memory remained static.