meltingice/CamanJS

Way to disable the store

avandecreme opened this issue · 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.

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

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.

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.

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