Freeze... detection?

114 views
Skip to first unread message

Nathan E.

unread,
Aug 18, 2012, 6:47:56 PM8/18/12
to phon...@googlegroups.com
No matter how much I comb over my application, I know that there are probably going to be some bugs that I can't find or fix. There are certain situations where the app just freezes, and though I'm sure it's because of my lack of coding skills, I'd like to know if there was a possible detection for it. For example, I made a coding mistake and ran the app, then when I got to a part that froze it, I hit the Home button and when back into it. Because of multi-tasking, it put me right where I was before... Now, I know I could four-finger swipe up and kill the app, then restart it, but many of my users don't. Is there a way that I can have the app crash if it freezes?

Kerri Shotts

unread,
Aug 18, 2012, 8:12:23 PM8/18/12
to phon...@googlegroups.com, phon...@googlegroups.com
You're trying to solve the wrong problem, IMHO. The idea is not to have any freezes in your app (that the user would notice terribly -- but preferably none at all). The user shouldn't generally ever have to think about how to kill an app (though chances are good users of certain apps are pretty good at it). 

Instead, concentrate on not freezing the app in any way. You can do some of this by avoiding infinite loops (it's easy enough to put a "bail" in the loop, say after some large number of iterations [outside the normal range], kill the loop). Put console logging all over the place so that you can identify places where freezing occurs so that you can concentrate on optimizing those portions.

If possible, break your work up into smaller tasks that can be done quickly across multiple sessions. You can do this with setInterval to schedule the task in periodic intervals. Just make sure the task is completed quickly.

Now, to your question at hand, you're essentially asking about a watchdog timer -- a timer that detects the non-response of the target and if it exceeds a certain period, kills and optionally restarts. iOS already does this in the case of a truly frozen app -- the watchdog upon starting or resuming an app permits 10s of non-responsiveness. If the app doesn't respond in that time, the app is killed. (It is not restarted.)

If iOS isn't killing your app in those instances after 10s, it means the app isn't really frozen, but non-responsive to your input. There are lots of ways to make that happen, but an easy way is to simply drop an invisible DIV that covers your entire app area. Instant non-responsive app, but as far as iOS is concerned (and the app is concerned), everything's hunky-dory. Essentially, be sure to avoid covering touchable areas with blocking elements without providing a timeout (via setTimeout) to clear those touchable areas after a given period (say 30s, 1m, etc.) (Granted, this looks the same to the end user as a frozen app. But no watchdog could ever catch this, since the app isn't really frozen.)

Examples:

1) BAILing loops

bail=0;
while (x != y && bail < 10000)
{
  x = someNextValue();
  bail++;
}

The loop will bail after 10000 iterations, no matter what. Of course, you have to make sure that 10000 is outside the normal expected range.

2) Split tasks

var id = setInterval ( function ()
                                 {
                                   if (taskIsDone) { clearInterval (id); return; }
                                   doShortTask();
                                 }, 100 );

This executes doShortTask() every 100ms until the task is complete.

3) If blocking interaction, provide a timeout:

someDIV.style.display = "block"; // this blocks all interaction
setTimeout ( function () { someDIV.style.display = "none"; 
                                        console.log ("timeout"); }, 30000 );
doSomeLongAsynchronousRequest(); 

If doSomeLongAsynchronousRequest() takes longer than 30s, the blocking DIV will be hidden. The action isn't stopped, granted, but at least the app no longer appears to be frozen. (Finding some way to cancel the long action would also be wise.)

Hope that helps?



______________________________
Kerri Shotts
photoKandy Studios LLC

📱 Phone: +1 (312) 380-1035
🌐 Web: http://photokandy.com 

Twitter: @photokandy


On Aug 18, 2012, at 17:47, "Nathan E." <nathan...@gmail.com> wrote:

No matter how much I comb over my application, I know that there are probably going to be some bugs that I can't find or fix. There are certain situations where the app just freezes, and though I'm sure it's because of my lack of coding skills, I'd like to know if there was a possible detection for it. For example, I made a coding mistake and ran the app, then when I got to a part that froze it, I hit the Home button and when back into it. Because of multi-tasking, it put me right where I was before... Now, I know I could four-finger swipe up and kill the app, then restart it, but many of my users don't. Is there a way that I can have the app crash if it freezes?

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
 
 

Nathan E.

unread,
Aug 18, 2012, 8:14:40 PM8/18/12
to phon...@googlegroups.com
Thank you so much. That helps a lot; I just have a lot of code to go through because the errors don't seem consistent.

One thing I don't understand is this line in your response:
someDIV.style.display = "block"; // this blocks all interaction

I don't understand how setting the display CSS attribute to "block" stops interaction, but I rarely use it, so it might.... What's the deal with that?

Thanks again.

Kerri Shotts

unread,
Aug 18, 2012, 9:20:48 PM8/18/12
to phon...@googlegroups.com, phon...@googlegroups.com
I should have been specific-- this particular div would have a style like this:

position:absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index:1;

In this case, an invisible DIV would be over everything, if display is set to block. If none, the DIV would have no effect, and would let touch events through.



______________________________
Kerri Shotts
photoKandy Studios LLC

📱 Phone: +1 (312) 380-1035
🌐 Web: http://photokandy.com 

Twitter: @photokandy

Nathan E.

unread,
Aug 18, 2012, 9:20:43 PM8/18/12
to phon...@googlegroups.com
Ok, that makes sense. You are not talking about styling the button used for interaction, you are styling a div that covers the screen. I've used that before, but I've always been scared that JavaScript would freeze and render the entire app useless, but your suggestion helps a lot. Thanks again.
Reply all
Reply to author
Forward
0 new messages