google chrome app - Delete Javascript blobs? -


i'm having heck of time getting rid of these stupid things. i've got couple of chrome apps deal lots of media files; 1 of them able use bunch of "delete"s , window.url.revokeobjecturl stopped them building in chrome://blob-internals/, other one, nothing seems help. missing something? know when i'm done damn thing, there seems nothing can do.

specifically, i'm using file object in block this:

ref.file(function(f) {     // stuff...     // , i'm done!     delete f }); 

here's actual source of app:

https://github.com/pkulak/photo-importer

and here's 1 think solved problem, knows:

https://github.com/pkulak/drive-slideshow

this looks have memory leak.

javascript doesn't have "delete" in sense you're talking about, garbage collects properties , variables become orphaned. delete operator 1 such way achieve - removes definition of property object.
using delete correctly means using on property, not variable. reason works on variables because of happens var in global namespace (i.e. become properties of window). means can't delete parameter.

further, note once function has finished invoking, if there no references being kept alive of it's internals gc'd.

next, consider

var o = {}; o.a = []; o.b = o.a; delete o.a; 

what o.b now?

`o.b; // []` 

it's still pointing @ array though deleted o.a reference. means array won't garbage collected.

so mean you?

to rid of blobs, need destroy references them.

yes, revoking uri part of it, need remove references way through code. if you're finding difficult, i'd suggest wrap blobs can @ least minimise problem.

var myblob = (function () {     var key, o;     function myblob(blob) {         var url;         this.blob = blob;         blob = null;         this.geturl = function () {             if (url) return url;             return url = url.createobjecturl(this.blob);         };         this.dispose = function () {             if (url) url = url.revokeobjecturl(url), undefined;             this.blob = null;         };     }     o = new blob();     (key in o)         (function (key) {             object.defineproperty(myblob.prototype, key, {                 enumerable: true,                 configurable: true,                 get: function () {return this.blob[key];}             });         }(key));     o = key = undefined;     return myblob; }()); 

now, instead of regular blob creation use new myblob(blob) immediately make blob, keeping no other references blob. when you're finished blob, call mywrappedblob.dispose(); , should free gc'd. if it's really necessary pass blob directly, gave property myblob.blob.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -