Skip to content

Commit

Permalink
Merge branch 'loadScript_destory'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakearchibald committed Jul 28, 2009
2 parents e9a2c4b + 35a3eb5 commit f9337e4
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/net/net.js
Expand Up @@ -37,6 +37,7 @@
* @type String
*/
globalObjectName = "_" + glow.UID + "loadScriptCbs",
$ = glow.dom.get,
events = glow.events,
emptyFunc = function(){};

Expand Down Expand Up @@ -299,20 +300,19 @@
globalObject = window[globalObjectName] || (window[globalObjectName] = {});

//assign onload
if (opts.onLoad) {
if (opts.onLoad != emptyFunc) {
globalObject[callbackName] = function() {
//clear the timeout
request._timeout && clearTimeout(request._timeout);
//set as completed
request.completed = true;
// call the user's callback
opts.onLoad.apply(this, arguments);
// cleanup
glow.dom.get(script).destroy();
// clean up references to prevent leaks
script = scriptElements[newIndex] = globalObject[callbackName] = undefined;
// cleanup references to prevent leaks
request.destroy();
script = globalObject[callbackName] = undefined;
delete globalObject[callbackName];
delete scriptElements[newIndex];
}
};
url = glow.lang.interpolate(url, {callback: globalObjectName + "." + callbackName});
}

Expand Down Expand Up @@ -551,6 +551,29 @@
abortRequest(this);
}
return this;
},
/**
@name glow.net.Request#destroy
@function
@description Release memory from a {@link glow.net.loadScript} call.
This is called automatically by {@link glow.net.loadScript loadScript}
calls that have {callback} in the URL. However, if you are not using
{callback}, you can use this method manually to release memory when
the request has finished.
@example
var request = glow.net.loadScript('http://www.bbc.co.uk/whatever.js');
@returns this
*/
destroy: function() {
if (this._callbackIndex !== undefined) {
$( scriptElements[this._callbackIndex] ).destroy();
scriptElements[this._callbackIndex] = undefined;
delete scriptElements[this._callbackIndex];
}
return this;
}
};

Expand Down

0 comments on commit f9337e4

Please sign in to comment.