I have written a function for deleting object preiodically.
function add(variable, expireSecond){
this.list[variable] = {"expireSecond": expireSecond, "addTime": (new Date().getTime()) / 1000};
}
function deleteExpiredObject(){
var currentTime = (new Date().getTime()) / 1000;
for (var key in this.list) {
var item = this.list[key];
if (item.expireSecond + item.addTime < currentTime){
delete this.list[key];
}
}
}
When I use it, I tried to do the following:
add(xxx[1], 300);
But when I called deleteExpiredObject()
, it seems that the memory is not free after the object is expired. Is it due to non-zero reference of the object in xxx[1]
? How to solve? Is there any library I can use?
Thanks!