Quick way to crash APE: store a not so big array - out of memory

31 views
Skip to first unread message

Nicolas

unread,
Dec 4, 2014, 7:01:09 AM12/4/14
to ape-p...@googlegroups.com
Hi,

I am really puzzled by this one. I have been looking at memory issues (leaks?) in my program.

Here is a simple routine to make APE crash pretty quickly.

g_user_info=[];
for (var user_id=1;user_id<=10000;user_id++){
    Ape.log("user_id:"+user_id);
    g_user_info[user_id]=[];
    for (var i=1;i<=7;i++){
       g_user_info[user_id][i]=[];
    }
    
    //Ape.log(mydump(g_user_info));
}

To reproduce the crash, simply put this at the top of your commands.js file and run APE.

On my dev machine, APE reaches user_id=9,000. On my prod machine, even less, only 6,800.

I am really puzzled as to why such a small array should make APE crash. 7,000 * 7 is not such a big number, right?

So two questions:

1) Can you reproduce the issue?
2) Have you got an explanation? Am I doing something wrong here?

Thanks for your precious help.

Nicolas

unread,
Dec 4, 2014, 10:03:45 AM12/4/14
to ape-p...@googlegroups.com
Actually, this can even be simplified. There is no need for several loops. This is enough to make APE crash quickly.

for (var user_id=1;user_id<=1000000;user_id++){
    g_user_info[user_id]=[];
}

BTW, replacing [] by {} does not help (actually just a little, crashes come 50% later)

I strongly suspect the way memory is allocated to be the issue. Does anyone know how APE handles arrays?

There seems to be a small maximum.

peter.r...@verpeteren.nl

unread,
Dec 5, 2014, 4:00:27 PM12/5/14
to ape-p...@googlegroups.com
hai

In this case, the memory allocation is handled by the spidermonkey
engine.
I guess that the runtime enforces this as a limit. See
./src//modules/libape-spidermonkey.c#L5484
rt = JS_NewRuntime(8L * 1024L * 1024L);


Peter

Nicolas schreef op 2014-12-04 16:03:
> --
> --
> You received this message because you are subscribed to the Google
> Groups "APE Project" group.
> To post to this group, send email to ape-p...@googlegroups.com
> To unsubscribe from this group, send email to
> ape-project...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ape-project?hl=en [1]
> ---
> APE Project (Ajax Push Engine)
> Official website : http://www.ape-project.org/ [2]
> Git Hub : http://github.com/APE-Project/ [3]
>
> ---
> You received this message because you are subscribed to the Google
> Groups "APE Project" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to ape-project...@googlegroups.com [4].
> For more options, visit https://groups.google.com/d/optout [5].
>
>
> Links:
> ------
> [1] http://groups.google.com/group/ape-project?hl=en
> [2] http://www.ape-project.org/
> [3] http://github.com/APE-Project/
> [4] mailto:ape-project...@googlegroups.com
> [5] https://groups.google.com/d/optout

Nicolas

unread,
Dec 5, 2014, 4:54:19 PM12/5/14
to ape-p...@googlegroups.com, peter.r...@verpeteren.nl
Many thanks Peter. Very helpful.

I guess I have to recompile APE with bigger values.

Any idea why the limit is so low?

I figure a 100,000 array is very small and am very suprized noone else ever ran into this limitation.

Thanks again.


Nicolas

unread,
Feb 27, 2015, 9:16:31 AM2/27/15
to ape-p...@googlegroups.com, peter.r...@verpeteren.nl
Bingo!!

I changed to:

     rt = JS_NewRuntime(8L*8L * 1024L * 1024L); 

and even:

     rt = JS_NewRuntime(8L*8L*8L * 1024L * 1024L); 

It worked.

I can now generate 64 more objects!

Many thanks!

I strongly suggest to put this last line as default in APE. I don't see why this would be a problem (and I can tell you the existing line has caused me weeks of time!).

Thoughts?

PS: many many thanks Peter and Anthony!
Reply all
Reply to author
Forward
0 new messages