Ownership and dispose

From: Dominic (dominicsmith501_at_hotmail.com)
Date: 07/28/04


Date: 28 Jul 2004 16:19:31 -0700

This is going to sound like a newbie question, but I have done a fair
bit of C++. I'm just new to C# and .NET. I am trying to work out how
ownership and calls to dispose are commonly used (and what assumptions
people tend to make).

Here is an example, suppose I am writing my own MyListControl. I have
a class Item which represents an item in the list (text, color, image
index etc). There is a method of MyListControl.AddItem(Item item)
which adds an item to the list control.

Would you expect the control to keep a reference to item or make a
copy of item? Or would you just think either case to be equally likely
and verge on the safe side (assume the control keeps a reference).

This is important to the caller, because if a reference is kept, the
caller shouldn't modify andf re-use the object, or dispose it.

Dom