locked
Control's Tag Property memory usage & perofmance ? RRS feed

  • Question

  • Hi All,

    I have a collection of objects , which I am binding to a control , lets say TreeView ,  Now if I set to Tag property of TreeviewItem to object of that collection ,  then would that create a new object in memory and assign to Tag property of TreeViewitem or just create a reference to the Collection of Objects ?

    I want to set the Tag property but not sue how much impact it will have on memory usage & performance ?

    Thanks for you support.

    Friday, April 16, 2010 8:05 AM

Answers

  • Since you say "object", I assume the items in the collection are of a reference type. In that case, no new objects will be created.
    Mattias, C# MVP
    • Proposed as answer by HamAndFig Friday, April 16, 2010 2:13 PM
    • Marked as answer by Harry Zhu Friday, April 23, 2010 1:33 AM
    Friday, April 16, 2010 1:00 PM
  • Yes it is. You will have only one instance and both of the references (including Tag) will point to same memory in managed heap.

    Ram

    • Marked as answer by Harry Zhu Friday, April 23, 2010 1:34 AM
    Friday, April 16, 2010 2:42 PM

All replies

  • Since you say "object", I assume the items in the collection are of a reference type. In that case, no new objects will be created.
    Mattias, C# MVP
    • Proposed as answer by HamAndFig Friday, April 16, 2010 2:13 PM
    • Marked as answer by Harry Zhu Friday, April 23, 2010 1:33 AM
    Friday, April 16, 2010 1:00 PM
  • Yes, its collection of my custom objects.

    So its safe to assign Tag property of control to corresponding object.

    Thanks.

    Friday, April 16, 2010 2:33 PM
  • Yes it is. You will have only one instance and both of the references (including Tag) will point to same memory in managed heap.

    Ram

    • Marked as answer by Harry Zhu Friday, April 23, 2010 1:34 AM
    Friday, April 16, 2010 2:42 PM