I have an application that caches several codefluent objects.When I put several of those cached objects in a temporary collection the collection is never released from memory. By profiling the application with ANTS I found the villan: an eventhandler that is attached when the object is inserted in the collection in the 'BaseAdd' function of the collection.
cwProperty.KeyChanged += new System.EventHandler<CodeFluent.Runtime.Utilities.KeyChangedEventArgs<System.Guid>>(this.OnItemKeyChanged);
How can I prevent this eventhandler to be attached or how can I clean this up?
The default collection type for an entity is ListCollection
. Thus the generated collection store the data in a list
and a dictionary
. This allows to access an item by its index or its key. When you add an item in this collection, the collection needs to register the KeyChanged
event so it can update the dictionary when needed. When you remove an element from the collection, the event is detached.
If you never access items using their key, you can change the collection type to List
. Thus, there is no dictionary so no need to register the KeyChanged
event.
<cf:entity name="Customer" setType="List">
<cf:property name="Id" />
<cf:property name="FullName" />
</cf:entity>