On Tue, Sep 22, 2015 at 3:56 AM, Jane Chen <[email protected]> wrote: > I have something similar in my app and I'd like my background thread to > check the heap statistics to detect that the script is about to run out of > memory, so that I can terminate it before it actually does. > > My problem is that I don't know the criteria to detect that. I got from the > HeapStatistics: total heap size, total heap size executable, total physical > size, used heap size and heap size limit. I can see that my total heap size > and used heap size both grow with used heap size lagging slightly, heap size > limit stays constant. But way before total heap size reaches heap size > limit, I already get out of memory exception: > > ...... > 2015-09-21 18:21:49.290 Info: total heap size: 600510208 > 2015-09-21 18:21:49.290 Info: total heap size executable: 4194304 > 2015-09-21 18:21:49.290 Info: total physical size: 3928224 > 2015-09-21 18:21:49.290 Info: used heap size: 596191056 > 2015-09-21 18:21:49.290 Info: heap size limit: 1535115264 > ...... > 2015-09-21 18:21:56.294 Info: total heap size: 1023430400 > 2015-09-21 18:21:56.294 Info: total heap size executable: 4194304 > 2015-09-21 18:21:56.294 Info: total physical size: 3944864 > 2015-09-21 18:21:56.294 Info: used heap size: 1019090648 > 2015-09-21 18:21:56.294 Info: heap size limit: 1535115264 > > Any idea on how the out of memory condition can be detected based on the > above?
I don't think there is a bulletproof way to do that. There are two OOM scenarios: 1. The garbage collector can't reclaim enough heap space to allocate a new object. 2. V8 can't mmap the memory it needs to grow the heap. You can try to apply some best effort heuristics to the first scenario but the second one is essentially unpredictable. -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
