14

I came across this property while reading about JavaScript memory leaks. I was informed that this property is supported only in Internet Explorer and is responsible for circular reference.

I tried to check and found this property not available in any of the browsers. Can anyone offer any insight on this property and how is it linked to memory leaks?

abbotto
  • 4,259
  • 2
  • 21
  • 20
alter
  • 4,320
  • 7
  • 31
  • 36

3 Answers3

13

I came here with the same question, also after reading an article about memory leaks. I was still confused after reading the answers here, so I thought I'd share my findings after some more research.

It can be confusing in JavaScript to know if something like .expandoProperty is part of the language or somebody being clever with property names.

obj.expandoProperty in the memory leak article could just as well have been obj.foo. The point they are trying to get across by using ".expandoProperty" is that the property did not exist as part of the object originally.

var obj = {myProp: ''};
obj.myProp    = 'foo';  //myProp is not an expando property
obj.myNewProp = 'bar';  //myNewProp is an expando property

Add to the mix: .expando is an IE-only property that "sets or retrieves a value indicating whether arbitrary variables can be created within the object." MSDN article

See also generalized discussion of expando properties on StackOverflow here.

Community
  • 1
  • 1
Greg Perham
  • 1,835
  • 1
  • 17
  • 26
  • 4
    The question did not ask about memory leaks, but it does have that tag, sooo.... Code like the example above will never cause memory leak problems. The trouble seems to come into play when adding a property to a DOM element that refers to the very same DOM element. (Maybe this would be a problem with any kind of object? IDK Every discussion I saw on memory leaks and expando properties/objects centered around DOM elements.) – Greg Perham Mar 02 '13 at 03:09
7

Simply put expando property is a property which does not exist originally. In Internet Explorer if you create such a property for a DOM element you may end up with a memory leak. Here is an example:

var div = document.getElementsByTagName('div')[0];
div.someProperty = true; // 'someProperty' is an expando property which may introduce a memory leak in IE

More info can be found in the Understanding and Solving Internet Explorer Leak Patterns

Atanas Korchev
  • 30,562
  • 8
  • 59
  • 93
  • 5
    I think the point here is that expando properties containing references to other elements may cause leaks, but not with primitives types as per your example. – James Westgate Nov 20 '14 at 09:26
3

I think you mean the expando Property... with a space, referring to the expando property of objects. It:

sets or retrieves a value indicating whether arbitrary variables can be created within an object.

Peter Ajtai
  • 56,972
  • 13
  • 121
  • 140