/    Sign up×
Community /Pin to ProfileBookmark

Is this cleaning resources corrently?

Hi guys

I am new to DHTML. Would really appreciate if some1 cud help me out. Having prbs with memory leaks….

Here is my code which is really simple ..
<HTML>
<HEAD></HEAD
<body onbeforeunload=”cleanup();”>
<div id=”parentDiv”>&nbsp</div>
<script>
var parentDiv = document.getElementById(“parentDiv”);
var childDiv = document.createElement(‘DIV’);
childDiv.id = “childNode”;
childDiv.innerHTML = “Hello World”;

parentDiv.appendChild(childDiv);

//cleanup();

function cleanup()
{
parentDiv.removeChild(childDiv);
childDiv = null;
parentDiv = null;
}
</script>
</BODY>
</HTML>

If I check this code using “Drip!” its show that there is a memory leak with childDiv. I would assume that my cleanup() function is not doing its job.
However, I explicitly called the cleanup() removing it from the onbeforeunload event, where it cleaned everything and DRIP! didnt show any memory leaks.

I am baffled .. can any1 point me as to what I am missing or where I am going wrong …

Many many thanks in advance.
Tyl

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Tyl spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...