Memory Leak with ReadOnlyBase derived object inside BusinessBase derived objectMemory Leak with ReadOnlyBase derived object inside BusinessBase derived object
Old forum URL: forums.lhotka.net/forums/t/7133.aspx
Cable posted on Thursday, June 18, 2009
This is a follow up to a discussion I had with Rocky at VSLive! Las Vegas last week.
I have BusinessBase derived objects that have ReadOnlyBase derived objects in them. When importing data from an access db and saving it to the new SQL DB, I received an OutOfMemoryException.
The leak disappears if I change the BusinessBase OnAddEventHooks to not subscribe to the BusyChanged, UnhandledAsyncException, and PropertyChanged events for IReadOnly objects or if I don't use managed backing fields and Load/Set/Get/Read Property methods in my business objects. Here's what I did to the OnAddEventHooks method in BusinessBase:
protected virtual void OnAddEventHooks(IBusinessObject child)
{
bool isReadOnly = child is IReadOnlyObject;
INotifyBusy busy = child as INotifyBusy;
if (busy != null && !isReadOnly)
busy.BusyChanged += new BusyChangedEventHandler(Child_BusyChanged);
INotifyUnhandledAsyncException unhandled = child as INotifyUnhandledAsyncException;
if (unhandled != null && !isReadOnly)
unhandled.UnhandledAsyncException += new EventHandler(Child_UnhandledAsyncException);
INotifyPropertyChanged pc = child as INotifyPropertyChanged;
if (pc != null && !isReadOnly)
pc.PropertyChanged += new PropertyChangedEventHandler(Child_PropertyChanged);
IBindingList bl = child as IBindingList;
if (bl != null)
bl.ListChanged += new ListChangedEventHandler(Child_ListChanged);
INotifyChildChanged cc = child as INotifyChildChanged;
if (cc != null)
cc.ChildChanged += new EventHandler(Child_Changed);
}
I've posted more detail and screen shots from Ants on my blog http://lovetocode.net
Let me know if you need any more details.RockfordLhotka replied on Saturday, June 20, 2009
Thanks for following up on this - I'll add it to the list of things to look at.t.kehl replied on Tuesday, May 24, 2011
Hi Rocky
Any update about this? - I use CSLA 4.1.0 and had similar problems.
Best Regards, Thomas
Miroslav Galajda replied on Friday, January 10, 2014
Hi,
I have observed the same leak. Even in the latest version Csla 4.5.500 the problem isn't resolved. The bug is closed but not resolved.
Do you think that the proposed solution (here in the first post) is OK?
Thank you
Copyright (c) Marimer LLC