CSLA .NET
From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books
Sign in
|
Join
|
Help
Home
Forums
Store
FAQ
Forums
»
CSLA .NET Framework
»
CSLA .NET discussion
»
Memory Leak with ReadOnlyBase derived object inside BusinessBase derived object
CSLA .NET Resources:
CSLA .NET home page
What is CSLA .NET?
Download CSLA .NET
CSLAcontrib project
Code generation index
Memory Leak with ReadOnlyBase derived object inside BusinessBase derived object
rated by 0 users
This post has 1 Reply | 2 Followers
Posts
1
Reply
Cable
Posted: Thu, Jun 18 2009 3:12 PM
rated by 0 users
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.
Posts
7,309
Reply
RockfordLhotka
replied on
Sat, Jun 20 2009 1:20 PM
rated by 0 users
Thanks for following up on this - I'll add it to the list of things to look at.
Rocky
Previous
|
Next
Page 1 of 1 (2 items) |
RSS
Please contact
Magenic
for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.
Why donate?
Copyright (c) 2006-2010
Marimer LLC
. All rights reserved.
Email admin@lhotka.net for support.