Dan Baker
Dan Baker

Reputation: 1827

Hom much memory does a Jquery Element Reference Take Up?

If I have a plugin that makes reference to the same JQuery objects constantly I figure I should cache the reference.

I was wondering if anyone knew off hand how much memory a jquery reference takes up?

Also I do understand that the price of the JQuery lookup far exeeds the price of the reference itself.

$('sameElement') 

vs

this.sameElement = $('sameElement'); 
this.sameElement

Upvotes: 6

Views: 329

Answers (1)

cookie monster
cookie monster

Reputation: 10972

It'll be the same as any other object reference, plus the memory of any of its own properties.

Its own properties are:

  • .length Number (64 bit) showing the current elements in the collection

  • .prevObject Reference to another jQuery object, which will hold reference to the previous set of elements (can be a memory leak in some cases)

  • .context Context element from which the selection was made

  • .selector Your selector string

Upvotes: 4

Related Questions