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

Re: [whatwg] Canvas 2D memory management

From: Robert O'Callahan <robert@ocallahan.org>
Date: Sat, 12 Jan 2013 11:36:00 +1300
Message-ID: <CAOp6jLZHobhSxsX6phrWRmiK0ZjWmQ_R3xGmQ5dak5iVedPKXA@mail.gmail.com>
To: Rik Cabanier <cabanier@gmail.com>
Cc: "whatwg@lists.whatwg.org" <whatwg@lists.whatwg.org>, Ashley Gullen <ashley@scirra.com>
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.)

Rob
-- 
Jesus called them together and said, “You know that the rulers of the
Gentiles lord it over them, and their high officials exercise authority
over them. Not so with you. Instead, whoever wants to become great among
you must be your servant, and whoever wants to be first must be your
slave — just
as the Son of Man did not come to be served, but to serve, and to give his
life as a ransom for many.” [Matthew 20:25-28]
Received on Friday, 11 January 2013 22:36:30 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 30 January 2013 18:48:12 GMT