• Canvas resources

    From =?UTF-8?Q?Jonas_Th=C3=B6rnvall?=@jonas.thornvall@gmail.com to comp.lang.javascript on Mon Nov 19 15:37:46 2018
    From Newsgroup: comp.lang.javascript

    My script has one rendering canvas, but also a few more or less static information canvases. Editing, settings, instruments etc. These static cavases are "hidden?" in button contexts, and only shown when repective button pressed.

    Now i wonder a bit about canvases, does all the canvases i created take up memory weither visible or not on screen?

    And does a static canvas also use any of the cpu? Can one, and should i, create and remove/revoke and reload the static canvases every time button the button for it pressed or is it just unnecessary work?

    If so how do one revoke "garbage collect?" a created canvas each time button closed?



    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From JJ@jj4public@vfemail.net to comp.lang.javascript on Tue Nov 20 10:39:19 2018
    From Newsgroup: comp.lang.javascript

    On Mon, 19 Nov 2018 15:37:46 -0800 (PST), Jonas Thörnvall wrote:
    My script has one rendering canvas, but also a few more or less static information canvases. Editing, settings, instruments etc. These static cavases are "hidden?" in button contexts, and only shown when repective button pressed.

    By "hidden in button contexts", I think you meant stored as a local variable
    in button event handler functions. Thus, not accessible elsewhere unless the canvas is placed onto the document.

    Now i wonder a bit about canvases, does all the canvases i created take
    up memory weither visible or not on screen?

    Yes. Otherwise, where would the pixel information be stored? Not to mention
    the canvas element's properties.

    And does a static canvas also use any of the cpu?

    Yes. At least when it needs to be displayed in the viewport. Whether
    hardware accelleration is used or not.

    Can one, and should i,
    create and remove/revoke and reload the static canvases every time button
    the button for it pressed or is it just unnecessary work?

    That'll only create garbages and temporarily waste memory. However, if performance is more important than memory usage, and if resetting the state
    of the canvas takes too long (for e.g. game restart/reset), the canvas can
    be simply dumped then create a new one. Efficiency tend to be slow, and performance tend to be memory hungry.

    If so how do one revoke "garbage collect?" a created canvas each time
    button closed?

    You can't control the garbage collection process. You'll have to simply
    "tuck" it in and hide it, then show it again when you later need it.
    --- Synchronet 3.20a-Linux NewsLink 1.114