[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] [Typed Array] ArrayBuffer Method Request - Dispose



Hi,

On Sun, Feb 24, 2013 at 12:39 PM, Si Robertson <retromodular@gmail.com> wrote:
Hi,

I have been studying, and experimenting with, the WebGL API and the Web Audio API recently and have noticed a potential system memory related problem with typed arrays: there is no way to dispose of array buffers when they are no longer needed.

When working with WebGL and/or Web Audio, array buffers can consume large amounts of system memory. Some of these buffers can be treated as permanent/static buffers and reused during the lifetime of an application, but others are temporary and might only be used during a single function call, or might need to be replaced when additional resources are loaded into the application (e.g. game level assets).

It would be extremely useful for programmers if we could explicitly dispose of an array buffer when it is no longer required. Disposing of an array buffer would immediately release any system resources used by the array buffer (e.g. system memory) and reduce the array buffer's length to zero. This would also potentially reduce the amount of work the GC has to do when it eventually decides to clean things up.

I am requesting a single method to be added to the ArrayBuffer type:

interface ArrayBuffer {
    ArrayBuffer dispose();
}

Most of the other programming languages I use allow these types of arrays to be disposed, for good reasons :)

Hmm, yeah, this is actually interesting because in any other case I would be completely against manual memory management in JS, but typed arrays are quite special because from the application's point of view you can already do this (neutering, e.g. just transfer the array to a short-lived worker). So I think that if we add this, to the application the side effects should be the same as if the typed array had been neutered (i.e. the buffer length becomes zero and so on).

So, long story short, I can sympathize with your use cases (I've done a lot of audio synthesis in JS) and think this would be quite a useful addition.

Cheers,
Jussi
 
Regards,
Si Robertson