Reputation: 1827
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
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