Icarus
Icarus

Reputation: 63966

Does this leak in IE?

I have an aspx page that makes an Ajax request (using jquery) to a web service to return some data.

my onerror handler is something like this (not exactly but this is the idea):

onerror: function(status,xhr, whatever) {
  var objectResult = eval('('+xhr.Status+')');
  alert(objectResult.Message);
}

Question:

Will this create a potential memory leak due to the eval expression being assigned to my local var?

Thank you.

Upvotes: 1

Views: 239

Answers (2)

Cameron
Cameron

Reputation: 98776

This will definitely not result in a memory leak.

Your objectResult variable will be destroyed at the end of the function (since it's a local variable).

The actual object in memory that objectResult was referencing is then free to be garbage collected (since the only variable referencing it was destroyed). It probably won't be garbage collected right away, though.

Upvotes: 2

g.d.d.c
g.d.d.c

Reputation: 47988

No, this should not create a memory leak. The objectResult variable should be cleaned up as it leaves scope when your handler finishes.

Upvotes: 1

Related Questions