最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Delete object from memory in javascript - Stack Overflow

programmeradmin1浏览0评论

I am working on an AJAX application with a lot of Javascript. All pages are loaded through AJAX.
On a certain page I have a grid which is build in Javascript. Now when I leave that page I want to destroy that grid. I call jQuery.remove() but this only deletes the object from the DOM.
My question is how can I delete this grid object from the memory? Cause it still exists when I move away from the page.

Much appreciated!

I am working on an AJAX application with a lot of Javascript. All pages are loaded through AJAX.
On a certain page I have a grid which is build in Javascript. Now when I leave that page I want to destroy that grid. I call jQuery.remove() but this only deletes the object from the DOM.
My question is how can I delete this grid object from the memory? Cause it still exists when I move away from the page.

Much appreciated!

Share Improve this question asked Feb 25, 2011 at 8:22 GerardGerard 1,8695 gold badges18 silver badges21 bronze badges 5
  • 2 How do you know that this object still exists in memory after you navigate away from the page? – Darin Dimitrov Commented Feb 25, 2011 at 8:26
  • Do you store grid identifier in variable? If so then make gridVar = null; – CoolEsh Commented Feb 25, 2011 at 8:26
  • 1 It's pletely up to the browser... I guess you assume it still exist in memory because the browser process memory usage is not decreasing? – Shadow Wizzard Commented Feb 25, 2011 at 8:28
  • When I open the firebug console I can see the object still exists. It's only deleted from the DOM. – Gerard Commented Feb 25, 2011 at 10:21
  • firebug can't really tell what is in the memory and what isn't in the memory, I would look for more "reliable" tool if you're really into it. – Shadow Wizzard Commented Feb 27, 2011 at 8:52
Add a ment  | 

2 Answers 2

Reset to default 7

If you delete all references to your grid (i.e. assign null to the variable), the garbage collector will delete the object from memory.

put the grid into a div or anything you want. when you want to delete it use

$("<the name of the div>").empty();

that will clear it.

发布评论

评论列表(0)

  1. 暂无评论