System out of memory exception on row change

System out of memory exception on row change

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


kumar.harsh posted on Wednesday, March 12, 2008

Hi,
I am new to CSLA and am using v2.0.50727. I am getting a strange SystemOutOfMemoryException in my grids.

The basic structure is -

Class A1 : BusinessBase<A1>
{//some properties}

Collection A1Collection : BusinessListBase<A1Collection, A1>
{//childs A1}

Class A2 : BusinessBase<A2>
{//some properties
A1collection a1 = new A1collection();
}

collection A2collection : BusinessListBase<A2Collection, A2>
{//childs A2}

Now I bind A2Collection to a third party grid(Infragistics v7.3).On row change, i get a system out of memory exception.
The log says -

------------------------------------------------------------
    Type : System.OutOfMemoryException, mscorlib, Version=2.0.0.0, Culture=neutral,

PublicKeyToken=b77a5c561934e089
    Message : Exception of type 'System.OutOfMemoryException' was thrown.
    Source : mscorlib
    Help link :
    Data : System.Collections.ListDictionaryInternal
    TargetSite : Void set_Capacity(Int32)
    Stack Trace :    at System.IO.MemoryStream.set_Capacity(Int32 value)
       at System.IO.MemoryStream.EnsureCapacity(Int32 value)
       at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.IO.BinaryWriter.Write(Byte[] buffer)
       at System.Runtime.Serialization.Formatters.Binary.__BinaryWriter.WriteSingleArray(NameInfo
memberNameInfo, NameInfo arrayNameInfo, WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, Int32 length, Int32 lowerBound, Array array)
       at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo
objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)
       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.Core.BusinessBase.BeginEdit()
       at Csla.Core.BusinessBase.System.ComponentModel.IEditableObject.BeginEdit()
       at Infragistics.Win.UltraWinGrid.UltraGridRow.BeginEdit()
       at Infragistics.Win.UltraWinGrid.UltraGridCell.OnAfterCellEnterEditMode()
       at Infragistics.Win.UltraWinGrid.UltraGridLayout.OnEditorAfterEnterEditMode(Object sender,
EventArgs e)
       at Infragistics.Win.EmbeddableEditorBase.OnAfterEnterEditMode()
       at Infragistics.Win.EditorWithText.OnAfterEnterEditMode()
       at Infragistics.Win.EmbeddableEditorBase.EnterEditMode(EmbeddableUIElementBase
embeddableElement)
       at Infragistics.Win.UltraWinGrid.UltraGridCell.EnterEditorIntoEditMode(Boolean byMouse)
       at Infragistics.Win.UltraWinGrid.UltraGridCell.EnterEditMode(Boolean byMouse, Boolean
showingDropDown)
       at Infragistics.Win.UltraWinGrid.UltraGridCell.SetFocusAndActivate(Boolean byMouse, Boolean enterEditMode, Boolean byTabKey)
       at Infragistics.Win.UltraWinGrid.UltraGridCell.SetFocusAndActivate(Boolean byMouse, Boolean enterEditMode)
       at Infragistics.Win.UltraWinGrid.CellUIElementBase.OnEmbeddableElementMouseDown(Object sender, EmbeddableMouseDownEventArgs e)
       at
Infragistics.Win.UltraWinGrid.GridEmbeddableEditorOwnerInfoBase.OnEditorMouseDown(EmbeddableUIElementB
ase embeddableElem, EmbeddableMouseDownEventArgs e)
       at Infragistics.Win.EmbeddableUIElementBase.RaiseMouseDownEvent(EmbeddableMouseDownEventArgs e)
       at Infragistics.Win.EmbeddableUIElementBase.OnMouseDown(EmbeddableMouseDownEventArgs e, Boolean adjustableArea, UIElement& captureMouseForElement)
       at Infragistics.Win.EditorWithTextUIElement.OnMouseDown(MouseEventArgs e, Boolean adjustableArea, UIElement& captureMouseForElement)
       at Infragistics.Win.UIElement.OnMouseDown(MouseEventArgs e, Boolean adjustableArea,
UIElement& captureMouseForElement)
       at Infragistics.Win.TextUIElementBase.OnMouseDown(MouseEventArgs e, Boolean adjustableArea, UIElement& captureMouseForElement)
       at Infragistics.Win.EditorWithTextDisplayTextUIElement.OnMouseDown(MouseEventArgs e,
Boolean adjustableArea, UIElement& captureMouseForElement)
       at Infragistics.Win.ControlUIElementBase.ProcessMouseDownHelper(Object sender,
MouseEventArgs e)
       at Infragistics.Win.ControlUIElementBase.ProcessMouseDown(Object sender, MouseEventArgs e)
       at Infragistics.Win.Utilities.ProcessEvent(Control control, ProcessEvent eventToProcess, EventArgs e)
       at Infragistics.Win.UltraControlBase.OnMouseDown(MouseEventArgs e)
       at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

------------------------------------------------------------

What could be possibly going wrong?

Also if I do not fill the child collection, and only bind the main A2collection with A2.A1collection = null, it takes a few row change clicks before this error appears again, and keeps on popping on subsequent rowchange events.
Can somebody please help me on this?

csanchez replied on Wednesday, March 12, 2008

Hi:

Don't know if this would help you but I had a similar problem.

In my framework I was maintaining a parent field. That parent field was being copied in the CopyState method everytime my grid interface call BeginEdit. The parent include my actual object which was copied again and again during this process throwing eventually a OutOfMemory exception.

What I did was mark that parent field as [NotUndoable]. That fixed my problem.

Hope this helps you.
Christian.

kumar.harsh replied on Thursday, March 13, 2008

Hi thr,
I am not using a parent field anywhere. the structure only has a child collection.The child has no reference of parent. 
Also have seen the RAM usage go up on clicking on rows. If I do not click on any other row, the usage does not go up. So it is surely not recursive.
I also wanted to ask...how does undo work in such structure? Does it copy whole collection onto the stack while only one variable in a child is edited ? If its so, it is bound to take so much memory.

MichaelWaihenya replied on Tuesday, November 18, 2008

Hi

Dis you ever find a solution for this?

 

Copyright (c) Marimer LLC