02-10-2011 10:58 AM
Will the QNXApplicationEvent.LOW_MEMORY only trigger for apps in the background, or will it also be dispatched to active applications?
If it's the latter, let's say your app is in the form of a game. How do you respond to the event if they are in the middle of it?
Do you make a dialog, like "Warning! Your device is running low on memory. Please end other processes in order to continue this game." ?
Or do you wait it out, hoping that other running applications will free up memory, solving the problem?
02-10-2011 11:04 AM
It should get triggered if you are active or in the background.
You should save any state that you have.
The OS will shut down apps that have not been used for awhile in hopes to free up memory.
I would not put up an alert, but some indication (passive) that memory might be running low in the app bar or other part of the application might be a good idea, but I would wait until you get an actual PB to see if this will be a problem or not.
02-10-2011 11:06 AM
according to the Development Guide:
it mainly deals with applications in the background that are in danger of being closed to free up memory. so you should save the state of your application if the memory starts to decrease and the trigger is received by your app. the event will also be received by apps not in the background and are currently being used.
if you get a low memory event when the user is using your app, the safest bet is to save the current state of your app and let the user know whats happening that way they dont get too angry when something crashes (whether its your app or other apps running). people like to know whats going on rather than be surprised. so if you let them know that you were notified of a problem, then they'll appreciate it more im sure.
02-10-2011 11:16 AM
I still would not put up an alert in response to a low memory event. Depending on how the OS dispatches these events, the user could get a bunch of alerts, especially if more than one open app does this. Passive notification (after saving state) at most. Flashing icon somewhere that they can click on (e.g. scull and cross bones), to see what is going on -- then show an alert.
02-10-2011 11:36 AM
@jtegen: i agree. it'd be annoying to have to close every pop up about low memory. if we were to notify its best if is unintrusive and subtle enough to have the user know it happened and not interfere with normal usage of the playbook.
02-10-2011 12:27 PM
Keep in mind that it could be from your app or some other app. If it's your game app that's consuming too much memory, probably from a memory leak because it's buggy, then the user might not notice anything for a while, but all the inactive apps would be getting terminated quietly out of view.
Your game may keep running, until it's all by itself but sucking up all of system memory. Depending on memory conditions (how much the terminated apps were using), your app may get additional LOW_MEMORY notifications, as the background apps are terminated and memory is freed but then your game keeps sucking it away.
At the very absolute least, consider showing a notification when you get two consecutive notifications while your app is still the only one that's active. (That is, reset the count every time you are reactivated.) I'm guessing a bit, but I believe that would most likely be indicating that a background app was killed, but memory kept getting drained. It may not be your app doing it, but the user really should be alerted in some fashion.
You can also attempt to monitor how much memory your own app is consuming using the data from flash.system.System. You could measure memory during testing (but probably not with debug mode enabled) and integrate some value above that into your code as a "max expected usage", if that's possible with your app. Then, if you get a LOW_MEMORY event and your memory check tells you you're above that threshold, there's a chance you've got a leak and should let the user know there may be a problem. Of course, far better to test fully and be sure there isn't one before you release.
Most of the above is speculation, random pondering, and untested advice, so consider it worth up to the limit of how much you paid for it. ;-) Writing it gave me some ideas for my own use though...