IList<T> Custom Collections
Ken Alexander
Posts: 2
When using IList<T> for a custom collection. It appears that the underlying array is left in memory after the collection has been GC'd. It says 1 live instance of a size of 16 bytes.
I don't understand why it is left in memory. Any ideas would be appreciated.
Thanks,
Ken
I don't understand why it is left in memory. Any ideas would be appreciated.
Thanks,
Ken
Comments
This should help you identify what's keeping the remaining instance in memory.
Stephen
If you take another snapshot does the instance still remain?
Stephen
After pressing button2, I have [GC Handle]->System.Object[]->MyInfoClass[] chain and it's remained in memory after new snapshots. Any ideas why?
System.Generic.List contains a static reference to an empty array, so that it can represent 0 item lists more effectively: that's the array that you're seeing after you click the button. Note that it's actually there beforehand as well: you'll see two arrays when you take a snapshot before clicking the button.
It's not a memory leak, but rather an implementation detail of the .NET framework. You'll note that the array is always very small and there's only every one of these.
The pattern [GC Handle]->System.Object[]->MyInfoClass[] usually indicates a static variable: this is how they're implemented internally by the .NET framework. The profiler does try to identify which variable contains a particular object provided you're using .NET 2 or later, but there are some CLR limitations that prevent it from working reliably in all cases. Generic classes, such as List<T> is one such example, unfortunately, which is why this gets presented in this way.
Software Developer
Red Gate Software Ltd.