Been trying to find this bug for days now with no solution. Developing a ios game uising swift and only UIKit. My app displays a lot of small images (about 70 a time). Some uianimations are running repeatingly. After a while my app show some performance lags (tested on a device). Xcode shows only 30MB of memory usage and about 97% CPU time used. Using instruments didnt really help (im not using a lot of memory anyway). How can I track this bug down, this seems so weird to me.
The problem is that using UIKit for such graphics is not the best solution, as it is working through CPU, not GPU. And this is the reason, why application is lagging.
The other reason for it to show only 30MB of memory used, as it does not show memory used for uncompressed images. When you display image on the screen, or use UIViews with drawRect:, it takes really a lot of memory.
Related
I've been encountering some problems when testing my app from XCode to my iOS 6.1.6 iPod touch 32GB. For my game, images frequently fall and I am not sure if that is the problem. Someone told me that my app could be running slow because I have too much memory on my iPod, but I already cleared most of my memory.
My question is, how can I make my app run fast on my device?
It runs really smooth on my iOS Simulator but it's terrible after 5 seconds when tested on my device.
The code that makes my images fall is like this
imageView1.center = CGPointMake(imageView1.center.x+pos.x,imageView1.center.y+pos.y);
imageView2.center = CGPointMake(imageView2.center.x+pos.x,imageView2.center.y+pos.y);
imageView3.center = CGPointMake(imageView3.center.x+pos.x,imageView3.center.y+pos.y);
imageView4.center = CGPointMake(imageView4.center.x+pos.x,imageView4.center.y+pos.y);
pos = CGPointMake(0.0, 3.0);
I also have a timer set at 0.03.
Also, when every image falls, when it hits the bottom, a new image is made out of random. It's a loop.
Any UIKit operations frequently occur take a load on your iPods processor. Your mac CPU is so much faster and you've got a ton of more ram so that's why it works on the simulator. You could try reducing the frame rate (the timer interval) and see if that solves the problem. I'd suggest you stay away from UIKit for making games and instead use the new iOS 7 framework, SpriteKit. (A google search will find the documentation) Frameworks like SpriteKit or Cocos2d are slightly more difficult to learn, but they have engines optimized for running games and using your iPods gpu. How complex is your game? If it's more than just one screen with moving objects I'd consider rewriting the entire thing in SpriteKit. Sorry to let you down on your first game but UIKit is nearly never the way to go when making games. Good luck!
I'm looking for solution of animation about 50 images on retina iPad each has 2048*1536 size. I want to animate them on finger move(change images on uiimageview sync with touches moved event). Images loads slowly and animation freezes. I want to find any solution to solve that problem. Thanks.
There are a couple of issues that make this situation very hard to deal with. First, the memory usage of 50 full screen images is very large. For some background on how much memory that actually requires, see this blog post Video and Memory usage on iOS devices. The second issue you have run into is CPU usage. A retina iPad has multiple CPUs, but decoding huge PNG images still takes a lot of CPU cycles and that will prevent the animations from running smoothly. So, the only way you will get this to work well is to avoid decoding the image data at runtime and also avoid holding all the decoded data in memory because that would crash the device. The best solution is to simply mmap() all the decoded data and decode it ahead of time, that makes it possible to blit image data into CoreGraphics without actually having to copy the data. If you would like to use my library that does all that, it is linked at the bottom of the blog post.
Currently I am working on an Air app for iOS and Android. Air 3.5 is targeted.
Performance on iPhone 4 / 4s has been acceptable overall, after a lot of optimising: gpu rendering, StageQuality.LOW, avoiding vectors as much as possible etc. I really put a lot of effort in boosting performance.
Still, every once in a while, the app becomes very slow. There is no precise point in time or action or combination of actions after which this occurs. Sometimes, it doesn't occur for days. But when it occurs, only killing the app and launching it again helps, because the app stays slow after that. So I am not talking about minor hiccups that
The problem occurs only on (some) iPhones 4 and 4s. Not on iPad 3,4, iPhone 5, any Android device...
Has anyone had similar experiences and pointers as to where a solution might be found?
What happens when gpu memory fills up? Or device memory? Could this be involved?
Please don't expect Adobe Air to have performance as Native Apps. I am developing App with Adobe Air as well.
By the sound of your development experience. I think it's to do with memory issue, because the performance is not too bad at the begging stage, but it gets bad overtime (so u have to kill the app). I suggest you looking into memory leaking issue.
Hopefully my experience can help you.
I had a similar problem where sometime during gameplay the framerate would drop from 30fps to an unrecoverable 12fps. At first I thought I was running out of GPU memory and it was falling back on rendering with CPU.
Using Adobe Scout I found that when this occurred, the rendering time was ridiculousness high.
Updating to Air 3.8, I fixed the problem by limiting the amount of bitmaps that were being rendered and in memory at once. I would only create new instances of backgrounds for appropriate levels, and then flagging them for garbage collection when the level ended, waiting a few seconds and then moving to the next level.
What might solve your problem is if you reduce the amount of textures you have in memory at one time, only showing the ones you need to. If you want to swap out active textures for new ones, set all the objects with that texture data to null:
testMovieClip = null;
and remove all listeners from it so that garbage collection will pick it up.
Next, you can force garbage collection with AIR:
System.gc();
Instantiate the new texture you want to render a few frames after calling gc. Monitor resources with Scout and the iOS companion app to confirm that it's working.
You could also try to detect when the framerate drops, and set some objects to null then force garbage collection. In my case, if I moved my game to an empty frame for a few seconds with garbage collection, the framerate would recover and the game would resume rendering with GPU.
Hope this helps!
We have a memory-intensive 3D app which is primarily targeted at iPad 2 and iPhone 4S, but it works on iPod Touch 4G and iPhone 3GS as well. We have found that the smaller memory footprint on the iPod Touch 4G, combined with the retina display, makes this platform more susceptible to out-of-memory errors. iOS5 also seems to have lowered the available memory somewhat.
It's relatively easy for us to lower the resolution of 3D models, based on the platform we're using, but we have to set that resolution before loading, and thus we cannot effectively lower it dynamically based on memory pressure warnings from the O/S.
We've tuned the memory usage based on trial and error, but we've found that devices that haven't been rebooted in a long time (e.g., months) have a lot less useable memory than devices which have been rebooted recently. (Even if you kill off all the running apps.)
I'm wondering what other iOS app developers use as their practical memory limit for iPod Touch 4G apps?
While keeping all the caveats that everyone is offering in mind, my personal general rule of thumb has been that in sensible weather you can expect to have around the following:
512MB device -> 200MB usable (iPhone 4-4S, iPad 2)
256MB device -> 100MB usable (iPhone 3GS, iPad, iPod Touch 3G-4G)
128MB device -> 50MB usable (iPhone 3G, iPod Touch 1G-2G)
And if you want to rigorously withstand insensible weather without otherwise making a point of being flexibly responsive with memory usage, you can halve those numbers, or even third them. But it will be fairly difficult to guarantee sterling reliability if you can't throw anything overboard when conditions become dire. It's more like a sliding scale of how much performance you're willing to throw away for how much reliability at that point.
In environment predictability terms, iOS is a lot more like the PC than a dedicated machine, for better and worse, with the added bonus of a drill sergeant for an OS.
Recently I found this awesome tool to find what is the maximum memory capacity of any iOS device. We can also find at which memory level we received the Low Memory warning.
here is the link: https://github.com/Split82/iOSMemoryBudgetTest
It's hard to give an actual number because of all the external allocations the OS does on your behalf in UIKit and OpenGL. I try to keep my own allocations to around 30MB, with 50MB sort of my top end. I've pushed it as high as 90MB, but I got jettisoned a lot at that level so it's probably a bad idea unless the task using all that memory is very brief.
If you need to hack around your current problem you could just detect the problematic devices up front and turn down your graphics engine's resolution at startup. You can get exact device info or you could check for display scaling (retina) combined with number of processor cores and amount of RAM to determine what quality level to use.
I've had great success reducing my memory usage by using mapped files in place of loading data into RAM and you may want to give that a try if you have any large data allocations.
Also watch out for views/controls leaking from UIKit as they consume a lot of memory and can lead to being jettisoned at seemingly random times. I had some code which leaked child views from several view controllers. Eventually those leaks would chew up my app, though my app's memory usage didn't reflect the problem directly.
I am working on an iPad app that includes lots of images, animations and videos. My app crashes after running 12 to 13 minutes. Allocations show me only 3 MB memory usage while in VM Tracker dirty memory continuously increases till it reaches 130 MB and then app crashes. But VM Tracker does not give me any insight about what is actually happening in the code and which piece of code is responsible for increasing dirty memory. I am badly stuck with it. Have tried every possible thing. I am not using [UIImage imageNamed:], have avoided autoreleased objects as long as I can, have used autorelease pools where some convenience constructor is used. I am using FTUtils for animations in most places while in some places I am using [UIView beginAnimation:] but I am unable to reach any conclusion. Any help will be highly appreciated because I am badly stuck.