Here's a random question.
I have an object called Monkey, and an object called Banana. The Banana exposed an event called Ripens which the Monkey object subscribes to. When the Ripens event is triggered, the Monkey calls its Consume() function, which in turn destroys the Banana Object.
Example:
//And yes, I know this isnt real C# code. Just trying to get my point across and
//not necessarily be syntatically correct with this exmaple.
public class Banana
{
public event Ripens;
}
public class Monkey
{
public Monkey()
{
List<Banana> tree = new List<Banana>();
for (int i = 0; i < 8; i ++)
{
tree.Add(new Banana());
tree[i].Ripens += this.Consume;
}
}
public void Consume(Banana b)
{
tree.Remove(b);
b.Destroy();
}
}
So my question then is: Does the Monkey bleed memory for each banana that is destroyed without first unsubscribing from its events. Or do the event handlers in Monkey get destroyed along with the banana?