Is correction memory cosumption for Object Instance.

Hi all,

I have the following Class which when I create an Instance of takes up around 25KB. Is that normal. The properties are filled with ints and small strings, the Answer Collection only ever contains one instance, and the Questions Collection (m_colQuestions) contains between 1- and 30 (though rarely is it this high) of its self.

public class RecNspInspectionQuestion : MCS.PocketPC.Record, ICloneable
{
public enum Columns { QuestionTreeUID, ParentUID, QuestionTypeUID, QuestionNodeTypeUID, ShortDescription, LongDescription, IsActive, IsRequired, Reference, SortOrder, Notes, IsSystem, AnswerSetTypeUID, End };

public int m_nQuestionTreeUID = -1;
public int m_nQuestionTypeUID = -1;
public QuestionNodeType m_QuestionNodeType = QuestionNodeType.Undefined;
public int m_nParentUID = -1;
public int m_nAnswerSetTypeUID = -1;
public string m_strShortDescription = "";
public string m_strLongDescription = "";
public bool m_blIsActive = false;
public bool m_blIsRequired = false; // Is it required that this question be answered.
public string m_strReference = "";
public int m_nSortOrder = -1;
public string m_strNotes = "";
public bool m_blIsAnswered = false;
public bool m_blIsWrittenToDB = false;
public bool m_blIsSystem = false;
public int m_nAnswerStatus = 0;
public InspectionQuestions m_colQuestions = new InspectionQuestions();
public InspectionAnswers m_colAnswers = new InspectionAnswers();
public TblNspInspectionQuestionType.RecNspInspectionQuestionType m_objQuestionType = new TblNspInspectionQuestionType.RecNspInspectionQuestionType();
public TblNspAnswerSetType.RecNspAnswerSetType m_objAnswerSetType = null;

#region Constructor
public RecNspInspectionQuestion() { }
#endregion Constructor

public override string ToString()
{ return m_strShortDescription; }

public object Clone()
{
RecNspInspectionQuestion rec = (RecNspInspectionQuestion)this.MemberwiseClone();
InspectionQuestions colQuestions = new InspectionQuestions();
InspectionAnswers colAnswers = new InspectionAnswers();
//TblNspInspectionQuestionType.RecNspInspectionQuestionType objQuestionType = new TblNspInspectionQuestionType.RecNspInspectionQuestionType();
TblNspAnswerSetType.RecNspAnswerSetType objAnswerSetType = new TblNspAnswerSetType.RecNspAnswerSetType();

rec.m_colQuestions = colQuestions;
rec.m_colAnswers = colAnswers;
rec.m_objAnswerSetType = objAnswerSetType;

rec.m_objQuestionType = (TblNspInspectionQuestionType.RecNspInspectionQuestionType)this.m_objQuestionType.Clone();
// TODO: Clone objAnswerSetType.
return rec;
}

/// <summary>
/// Determines if the Question instance's Answer Object has Actions.
/// </summary>
/// <returns>True if Answer instance has Actions, else False.</returns>
public bool HasActionsOnAnswer()
{
if ((m_colAnswers.Count > 0) && (m_colAnswers[0].m_colActionAnswers.Count > 0))
return true;
else
return false;
}
}

(If it helps, would someone beable to direct me to a nice article that discusses memory allocation of objects etc)

Thanks in advance.



Answer this question

Is correction memory cosumption for Object Instance.

  • Sujeet Kuchibhotla

    You could use NETCF RPM to check the the allocation.

    http://blogs.msdn.com/stevenpr/



  • thukralz

    I’d say your estimate is wrong and you’re missing something like loaded libraries and JITed code. Besides, it does not matter how much memory it takes. What might matter is how many of these would fit in memory at the same time. If it’s not enough, you would need to load data from storage as needed, not all at once.



  • Jbud

    Would running the Remote Heap Walker VS application help in this scenario

    I can see that when this Object structure is loaded the Heap List grows quite big, and then when I view the Heap Dump on a Heap List I can see that certaining properties are allocated space, but they aren't even used up - many rows of '00 00 00 00 00 00' etc can be seen per block (what I am assuming is a property).


  • Teos

    It loads in the device memory ok (I can get around 30MB file on some instances), but the problem lies with when I get to a certain point of free program memory (around 19.5MB) then I get certain Symbol drivers not working (imager and scanner). It is really strange, as this problem only arises when I build up this Inspection object structure. When I don't build up this object structure then its fine. I'm wondering whether more memory is being used than what is actually being stated on the device.


  • JO91

    25K sounds like an awful lot for such a small class. How do you measure the memory consumption



  • Guennadiy Vanine

    I might have a serious problem here, but I don't really know how to tackle this.

    When I use Performance Monitor to my 'Managed Bytes Allocated' for the .NET CF GC object each time I load up this object structure the graph shows that it raises ten-fold.

    The Object structure is stored in a static property of a Class (which I believe statics do not get garbage collected), and this static is assigned on a specific Form, but when this Form closes, the static property is still alive and holding its memory, so the Managed Bytes Allocated remains the same. What seems worse is that each time I go to the Form that constructs this Object structure in memory (using the same static variable) it shows the Managed Bytes Allocated doubling each time the form is open, but the GC Heap is staying the same and the Managed Bytes In Use After GC goes up and down under the GC Heap Line.

    Now if I look in the Remote Performance Monitor that comes with CF2.0 SP1, the Managed Objects Allocated and Managed Bytes Allocated these increase by quite a bit each time I go onto the Form that builds Object - actually, my mistake, I think the Managed Bytes Allocated counter is the sum of the bytes allocated.

    The following is the Global Static Variable...

    protected static TblNspInspectionHeader.RecNspInspectionHeader objInspectionTree = new TblNspInspectionHeader.RecNspInspectionHeader();

    I'm just stumped as to how this Object Stucture (which contains around 210 objects) takes 6MB on the device. Does the CF allocate 4096 bytes for string objects, even though the string only contains a couple of characters

    Thanks


  • Mark Jewett - MSFT

    Its an estimation. The class is being used on a PocketPC, Compact Framework 2.0 (thought i'd post to this more specific forum, as I thought the theories behind memory allocation of Class might be the same.

    I have class Inspection, that contains a Collection of Questions Objects but this only contains one instance of a Question object, but its Collection of can contain many Questions Objects, and so on, but there is never more than 4 levels.

    Inspection
    Question
    ---> Question Collection
    ---> Question
    --> Question Collection
    ---> Question
    ---> Question
    ---> Question
    ---> Question Collection
    ---> Question
    ---> Question Collection

    When this is constructed, I use up around 6 meg (207 Question objects being created), so I got my estimation from that :)


  • Is correction memory cosumption for Object Instance.