I have an iPhone app that, for some users, sometimes behaves as if with the main UIView has been removed from the view hierarchy. It always happens coincident with a significant event in the game. Other Core Graphics-drawn UIViews that are above it in the z-order remain, but the main one (an OpenGL view) appears to be gone, leaving the background (a solid color).
The app does not crash (it keeps running, without the view), and this seems to happen very consistently for affected users. Unfortunately I am not able to reproduce it.
I suspect a memory issue -- that would be the easiest explanation -- but based on my reading it looks like didReceiveMemoryWarning only deallocs views that aren't visible, and aside from that the memory usage for my app is pretty small. Also, the "significant event" only results in OpenGL drawing and a SoundEngine call -- no view manipulation.
Anybody out there seen something like this before?
Yes, infact one of my applications very occasionally exhibits this problem and it does seem to be memory related.
I have had no success tracking it down either by debugging or analyzing the program flow. I have verified that the view in question is destroyed and not just hidden in some way.
It happens so infrequently that I haven't looked into it to deeply, but I do think it's caused by something in the OS in some way,
You can easily test low memory in the simulator to debug this problem if it is memory related.
The problem ended up being an uncaught NSException (from a third party library) thrown in the app's timer thread, which killed the timer thread but not the rest of the app. The good news is that crash reports are generated in this case, which can make tracking it down much easier if you know to look/ask for them.
As is made clear in the SDK documentation, when your app is running low on memory, views that are not in use can be collected. When it's needed again, it's re-created. This is to conserve precious iPhone resources. Your best bet is to retain the view so it can't be released.
Related
I'm working on porting an app from iOS to WinRT/8 Metro/8 Immersive/Whatever the current name is.
On iOS, we have the ability to set Application does not run in background to YES to cause the app to actually quit whenever the user leaves the app.
I would like to figure out how to replicate this behavior in WinRT.
Yes, I understand that this is abnormal behavior.
Yes, I have thought this through.
Yes, I have an extremely good reason for doing this.
I'm assuming that during the userLeavingApp event, I would just call Application.Current.Exit(), but I can't seem to find the userLeavingApp event. I thought about using OnSuspending (Handles Me.Suspending) in App.xaml.vb, but that doesn't seem to be called quickly enough for me.
Is there a .NET equivalent of viewWillDisappear or something?
Any ideas? This is an important security characteristic of my app, and I'd hate to have such difficulty in an entire platform due to such a small issue.
Thanks!
I'm not actually seeing Application.Current.Exit() working in OnSuspending; although as you mention the suspending isn't happening fast enough for you (which is by design). Throwing an exception there didn't work for me either.
There is Window.VisibilityChanged and if I issue Exit/exception there, it does shutdown the app when another app takes over. That said, VisibilityChanged will fire under other circumstances too so not sure if you could cover all the scenarios or rely on them not changing. See here for a bit more context.
To echo #Filip, whose response just popped in, it's highly unlikely you'll pass certification. An Exit() call is tantamount to an exception.
I don't think your app will pass certification if you call Application.Current.Exit(). If you are really confident this is what you want - I guess it is worth a shot to try. You could though simply unload anything that uses memory/CPU when you exit.
I recently have been getting memory warning messages when I load my app on my iPhone. I believe it has something to do with the storyboard that I recently switched over to from the classic .xib files. The app has been running a lot slower since and I don't get why. I got rid of a ton of my code that I was using for loading views, making tables, etc., so I would think that my app would run a lot faster now than it did before. My mainViewController (which is giving me the most problems), only has the default code in it! Is there a reason for this to be happening? Was the code running faster than storyboard or something?
Thanks in advanced.
Profile using Instruments to understand your app's execution -- CPU time (slow) and Allocations (memory consumption).
I have an application used mainly with uiwebview since we have a lot of work based on the website so it is quicker to show it directly on webview without re-coding it. The problem with webview, it is very expensive on memory. The UI is running fine throughout 10 times of going through from beginning of the application to the end of the application and repeating the process. On the other hand, the webview started to get slow when it doing some javascript animation using Canvas object. I have put in some code to remove NSUrlCache when it received warning.
Our application is based on navigating through stacked pages. When it gets to the end, user basically goes back to beginning. In my mind, I wanted to relaunch the application when I knows the application started to run slow. I know it is not a good idea to do this but I don't know what is the best way of reclaim the memory. I have looked through all of my code and have released what i have to released. The Application is going well without problem but it is just the uiwebview caused the performance.
Please Help...
Short answer: Not possible. You'll have to find a different way to address your performance problems.
If UIWebView is bottlenecking your application then the solution would be to NOT use UIWebView. You cannot simply "restart" or "reset" your application. If performance is decreasing over time as your app is being used then this suggests that you might not be managing your memory or object allocations properly. You can use the Leaks instrument to debug your application and try to hunt down memory leaks and you can use the Allocations instrument to analyze your object allocations.
Well, while running my iPhone game on my iPhone 4 through Xcode, my app crashed (sometimes does, sometimes doesn't), and when it crashed, Xcode didn't throw me any info. In the log, I could see (gdb) written, but nothing else that could help me find the problem.
What could cause such an error? At least it should tell me something, no?
Crashes without explanation on the device itself are often due to using up too much memory; the device simply terminates the app when it has requested more memory than available. This is easy to do in game development, with all those images.
Use Instruments to track memory usage, and/or put some good memory management code in the App Delegate methods for memory warnings and always release as much as you can.
I'm currently migrating the Fragaria framework from a GC-only environment to GC being supported. After the work was done (or what I thought had to be done to make it work) I was able to run the examples that come with the framework without any problems and Instruments didn't show any major memory leaks.
I included non-GC Fragaria in my non-GC application and it crashes as soon as I place the cursor on it. To be honest the usage pattern is different from the examples as I'm embedding it in an instance of NSViewController instead of NSDocument.
Can you give me some tips on how to debug this? I'm a bit lost on where to proceed now.
First thing to do is Build and Analyze the code, then fix any problems it finds.
Next, try running with Zombie detection enabled (google NSZombie).
Finally, each crash's stacktrace should give you a pretty good idea where things have gone off the rails.