W3C home > Mailing lists > Public > whatwg@whatwg.org > January 2013

Re: [whatwg] Canvas 2D memory management

From: Rik Cabanier <cabanier@gmail.com>
Date: Fri, 11 Jan 2013 14:56:41 -0800
Message-ID: <CAGN7qDDTvU7+staUdSmH9H7=i2p-4jZ6vbN7ZkpMBYRYcBs4pA@mail.gmail.com>
To: robert@ocallahan.org
Cc: "whatwg@lists.whatwg.org" <whatwg@lists.whatwg.org>, Ashley Gullen <ashley@scirra.com>
On Fri, Jan 11, 2013 at 2:36 PM, Robert O'Callahan <robert@ocallahan.org>wrote:

> On Sat, Jan 12, 2013 at 6:41 AM, Rik Cabanier <cabanier@gmail.com> wrote:
>> Some of you concerns with memory management could be addressed with
>> WeakMaps.
>> Basically, you can put all your images in a WeakMap and during the draw
>> cycle, you pull them out and use them. If they're no longer there, it
>> meant
>> that the garbage collector has kicked in to free up memory and you need to
>> reload (which will unfortunately cause a jank). I'm unsure how smart the
>> garbage collector is because you probably want the items in the WeakMaps
>> to
>> be deleted last.
> WeakMaps don't work like that. You can only test whether something is in a
> WeakMap by looking it up with a key object. If the key object stays alive
> and the WeakMap stays alive, then the value must also stay alive. On other
> hand, if the key object or the WeakMap have been collected, obviously you
> can't do the lookup. So you can't observe whether GC has happened using a
> WeakMap. (This is by design.)
> Sorry about that!
yes, you are correct that you can't use it that way.

Someone told me that WeakMaps work the same way as Flash's dictionary with
weak keys, but that is not the case.

FWIW, flash game developers use dictionaries with 'weak keys' as I
described earlier. If the memory runs low, the garbage collector will
delete objects from that cache.
Received on Friday, 11 January 2013 22:57:07 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:19 UTC