This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 23514 - <canvas>: Manual memory management for image assets used in canvas games
Summary: <canvas>: Manual memory management for image assets used in canvas games
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 enhancement
Target Milestone: Needs Impl Interest
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-14 22:08 UTC by Ian 'Hixie' Hickson
Modified: 2016-04-21 17:14 UTC (History)
3 users (show)

See Also:


Attachments

Description Ian 'Hixie' Hickson 2013-10-14 22:08:32 UTC
On Thu, 18 Jul 2013, Ian Hickson wrote:
> On Wed, 9 Jan 2013, Ashley Gullen wrote:
> >
> > Some developers are starting to design large scale games using our HTML5
> > game engine, and we're finding we're running in to memory management
> > issues.  Consider a device with 50mb of texture memory available.  A
> > game might contain 100mb of texture assets, but only use a maximum of
> > 30mb of them at a time (e.g. if there are three levels each using 30mb
> > of different assets, and a menu that uses 10mb of assets).  This game
> > ought to fit in memory at all times, but if a user agent is not smart
> > about how image loading is handled, it could run out of memory.
> >
> > [...]
> >
> > Some ideas:
> > 1) add new functions to the canvas 2D context, such as:
> > ctx.load(image): cache an image in memory so it can be immediately drawn
> > when drawImage() is first used
> > ctx.unload(image): release the image from memory
>
> The Web API tries to use garbage collection for this; the idea being that
> you load the images you need when you need them, then discard then when
> you're done, and the memory gets reclaimed when possible.
>
> We could introduce a mechanism to flush ImageBitmap objects more forcibly,
> e.g. imageBitmap.discard(). This would be a pretty new thing, though. Are
> there any browser vendors who have opinions about this?
>
> We should probably wait to see if people are able to use ImageBitmap with
> garbage collection first. Note, though, that ImageBitmap doesn't really
> add anything you couldn't do with <img> before, in the non-Worker case.
> That is, you could just create <img> elements then lose references to them
> when you wanted them GC'ed; if that isn't working today, I don't see why
> it would start working with ImageBitmap.
Comment 1 Justin Novosad 2016-04-21 17:14:59 UTC
This issue has been resolved thanks to the addition of the ImageBitmap API, and a more recent addition to that interface: the close() method which gives direct control over discarding the object's underlying image data without waiting for garbage collection.

See: https://github.com/whatwg/html/pull/1078