meltingice / CamanJS

Javascript HTML5 (Ca)nvas (Man)ipulation
http://camanjs.com
BSD 3-Clause "New" or "Revised" License
3.56k stars 406 forks source link

Way to disable the store #185

Open avandecreme opened 9 years ago

avandecreme commented 9 years ago

In my use case, I am creating and destroying a lot of canvases. However, every time I call Caman on one of them, it get cached and thus never released by the GC.

Is there a clean way to disable the store?

This is how I am doing it right now:

                var camanNoStore = function(canvas, callback) {
                    var storePutBackup = Caman.Store.put;
                    Caman.Store.put = function() {};
                    /* jshint newcap: false */
                    Caman(canvas, function() {
                        callback.bind(this)();
                    });
                    Caman.Store.put = storePutBackup;
                };

I can then call camanNoStore as I would call Caman.

avandecreme commented 9 years ago

Actually, I realized this hack doesn't work. So I can't find anything better than setting Caman.Store.put = function() {}; forever.

jocooler commented 9 years ago

Your hack might work if you used Caman.Store.items and set it to an empty object.

But can't you use Caman.Store.flush(name) to remove the ones you don't want? Or does that not work for you?

If you're up for editing the Caman file, you could probably also use the block of code in finishInit() to skip the store step:

Javascript:

 if (!Caman.NodeJS) {
       Store.put(this.id, this);
    }

Coffeescript (caman.coffee):

Store.put @id, @ unless Caman.NodeJS

which could be changed to something like

Store.put @id, @ unless Caman.NodeJS or Caman.DisableStore

And then set DisableStore to true on initialization.

avandecreme commented 9 years ago

Yes that would be the best option but I am not sure this project is maintained anymore so I am not willing to make a PR for now.

jnccneto commented 8 years ago

Hi I am facing the same problem. Any good fix for this? didn't want to change the source code. although it seems like a project closed right now