So emscripten_force_exit didn't work? Or restart it was the problem? Web worker sounds like the right way to go. Another possibility is to use dlmalloc's mspace (arena allocator). You can create_mspace a block of memory, call mspace_malloc, mspace_free etc with the additional mspace pointer, and destroy_mspace at the end to release all the memory at once. From
http://gee.cs.oswego.edu/pub/misc/malloc.h/*
mspace is an opaque type representing an independent
region of space that supports mspace_malloc, etc.
*/
typedef void* mspace;
/*
create_mspace creates and returns a new independent space with the
given initial capacity, or, if 0, the default granularity size. It
returns null if there is no system memory available to create the
space. If argument locked is non-zero, the space uses a separate
lock to control access. The capacity of the space will grow
dynamically as needed to service mspace_malloc requests. You can
control the sizes of incremental increases of this space by
compiling with a different DEFAULT_GRANULARITY or dynamically
setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);
/*
destroy_mspace destroys the given space, and attempts to return all
of its memory back to the system, returning the total number of
bytes freed. After destruction, the results of access to all memory
used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);