5

I'm getting a stackoverflow error in my service which is attached my to my main activity. Is there a way to change the stack size within my service ? I came across the Xss parameter, however, apparently its not available in the vm options (Help->Edit vmoptions).

A bit of the background: I'm getting the error when I try to read a serialized machine learning model in code and then de-serialize it. The same function works fine when this model is built on a small dataset, but doesn't work when I built the same model with a bigger daatset.

Any ideas on how can I do it ?

utengr
  • 3,225
  • 3
  • 29
  • 68

1 Answers1

4

You can't change the stack size of your app, however you can create a new thread and set the stack size for new thread using this constructor:

constructor Thread (ThreadGroup group, Runnable target, String name, long stackSize)

Anyway a new thread is a good idea as you get a clean stack. The Android main thread has already about 10 entries that belong to Dalvik and other parts of the system...

Robert
  • 39,162
  • 17
  • 99
  • 152
  • I don't want to change the stack size of the whole app but only the timer thread which I am using. I'm TIMER TASK and timer for a periodic task in my app. – utengr Nov 14 '16 at 11:38
  • You can't change the thread used by `Timer`. Hence you need a second thread with adapted stack size you can trigger from your `TimerTask`. – Robert Nov 14 '16 at 12:33