CamanJS icon indicating copy to clipboard operation
CamanJS copied to clipboard

Way to disable the store

Open avandecreme opened this issue 9 years ago • 4 comments

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 avatar Oct 23 '15 17:10 avandecreme

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

avandecreme avatar Oct 23 '15 19:10 avandecreme

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.

jocooler avatar Oct 27 '15 17:10 jocooler

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.

avandecreme avatar Oct 27 '15 17:10 avandecreme

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

jnccneto avatar Apr 27 '16 10:04 jnccneto