couple of times Undo cause System.OutOfMemoryException

couple of times Undo cause System.OutOfMemoryException

Old forum URL: forums.lhotka.net/forums/t/6539.aspx


fudongma posted on Monday, March 02, 2009

Our Windows application is using n-level undo functionality of CSLA.NET 2.0. I have lots of unused harddisk space, and the memory is 2GB. I only opened Window Outlook 2007 and our windows application on my machine. Afer small amount of changes, I can successfully undo. However, if I did lots of changes and then undo, I got exception error as followings:

Exception Information

=====================

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

   at System.IO.MemoryStream.set_Capacity(Int32 value)

   at System.IO.MemoryStream.EnsureCapacity(Int32 value)

   at System.IO.MemoryStream.WriteByte(Byte value)

   at System.IO.BinaryWriter.Write(Byte value)

   at System.Runtime.Serialization.Formatters.Binary.__BinaryWriter.WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, Int32 numMembers, String[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)

   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo, String[] memberNames, Type[] memberTypes, Object[] memberData, WriteObjectInfo[] memberObjectInfos)

   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)

   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)

   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)

   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)

   at Csla.Core.UndoableBase.CopyState()

   at Csla.BusinessListBase`2.CopyState()

   at Csla.BusinessListBase`2.Csla.Core.IUndoableObject.CopyState()

   at Csla.Core.UndoableBase.CopyState()

   at Csla.Core.BusinessBase.BeginEdit()

   at Win.UI.frmProfileMDIParent.UndoChanges(Boolean supressQuestion, Boolean closingParen)

Can anybody help??

Fintanv replied on Monday, March 02, 2009

Check your code.  You may have a reference back to a parent object that is not marked as notundoable.  This will cause a circular ref.

dheerajv replied on Thursday, August 13, 2009

hi,

   i am facing the same problem. i have checked the parent refrence but there is no such issue Please reply if you have any other idea.

Regards,

Dheeraj

RockfordLhotka replied on Thursday, August 13, 2009

How big is your object graph?

The exception is being thrown by the .NET serializer, so either you have some sort of circular reference, or your object graph must be massively huge.

nuno.s.alves replied on Monday, October 12, 2009

Hi,

i'm having the same problem.

What can i do to solve this problem?

Nuno Alves

RockfordLhotka replied on Monday, October 12, 2009

The most common issue is to have a circular reference in your object graph
(like a child referencing a parent - directly or indirectly). The solution
in that case is to add the NotUndoable attribute to the parent reference (or
equivalent) to break the circular reference.


-----Original Message-----
From: nuno.s.alves [mailto:cslanet@lhotka.net]
Sent: Monday, October 12, 2009 10:33 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] couple of times Undo cause
System.OutOfMemoryException

Hi,

i'm having the same problem.

What can i do to solve this problem?

Nuno Alves

nuno.s.alves replied on Tuesday, October 13, 2009

Hi,

i can't understand what you are saying.
Let me show you my scenario.

I have an object with multiple objects and some properties. When i load the object, sometimes my application return all the properties, when i try it again, the error comes up.

I can't say when it happens.

May you tell me where can i set this attribute?

RockfordLhotka replied on Tuesday, October 13, 2009

There are only a couple possibilities.

One is that your object graph is HUGE. Either many, many thousands of objects, or the objects contain very large data elements (really big strings, image data, etc).

The other is that you have objects that reference each other in a circular manner. This is the most common type of problem. For example, you might have a Person object that contains a collection of Address objects, and one of the Address objects references the Person object. That's a circular reference.

nuno.s.alves replied on Tuesday, October 13, 2009

thanks,

i didn't see your message.

Nuno Alves

nuno.s.alves replied on Tuesday, October 13, 2009

Ok,

i understand now what you mean.

But i don't have a circular reference. I only have an object with 5 objects. These are simple references.

One of the objects is a list of files and it's here where i can't understand because sometimes the application can load the object. When the error comes up, if i restart the application, i can load the object again.

Every time that the error comes up, i must restart the application to load the object.
After restart, it works again until the error comes up again.

I can't say when it happens because sometimes the object with the files is empty and the error comes up anyway.

What is the maximum size for an object?

RockfordLhotka replied on Tuesday, October 13, 2009

When you say "list of files" you mean a list of filenames (string values) or something else?

Many system-level objects, like file handles, aren't serializable and can cause all sorts of nasty issues.

nuno.s.alves replied on Tuesday, October 13, 2009

Well,

when i say list of files, i want to say list of documents, that each document has 1 MB and the list has 10 documents.

But i don't know if this is important, because some objects have any documents and the error comes up anyway.

Nuno Alves

nuno.s.alves replied on Tuesday, October 13, 2009

ok,

maybe i already know what is happening.

I start my application and open a process that shows me data from database. This object returns a list of documents.

For the first process it's all ok, but when i try to open another one, with documents the error comes up, because all memory (RAM) is full ! So i restart the application and i can open the process.

It's all about the documents.

Thanks, Nuno Alves

nuno.s.alves replied on Tuesday, October 13, 2009

Hi again,

thanks for your replay.

Let me show you my scenario.

I have an object with multiple objects and some properties. Sometimes i can load the object but if i try it again, the error comes up.

I can't say when it happens, because sometimes it doesn't happen.

May you tell me where can i add the NotUndoable attribute? or some page where i can see an example like mine?

Thanks, Nuno Alves

Copyright (c) Marimer LLC