views:

149

answers:

1

I've been told that Android OS stores all function calls in a stack. This can lead to many problems and cause the 'hiccups' during runtime, even if a program is functionalized properly, correct?

So the question is, how can we prevent this from happening? The obvious solution is to functionalize less, along with other sensible acts such as refraining from excessively/needlessly creating objects, performing static calls to functions that don't access fields, etc...

Is there another way though? Or can this only be done through careful code writing on the programmers' part? Does the JVM/JIT automatically optimize the bytecode during compile time to account for this??

Thanks a lot for your responses!!

+3  A: 

I've been told that Android OS stores all function calls in a stack

This is the way pretty much all programming languages work, and that has been the case for 30 or 40 years.

This can lead to many problems and cause the 'hiccups' during runtime, even if a program is functionalized properly, correct?

No, but it can lead to exceptions if you run out of stack space.

So the question is, how can we prevent this from happening?

How can you prevent what from happening?

The #1 culprit for running out of stack space is having too deep of a view hierarchy. Use hierarchyviewer to examine your activity, and count how many levels there in your view hierarchy, from PhoneWindow$DecorView to the farthest leaf node. If you get to around 15, you are likely to run out of stack space. In that case, simplify your UI, such as replacing nested LinearLayouts with a RelativeLayout.

CommonsWare