1

I've been developing a 3D viewer in XNA and Win-forms. I use a simple concept to save and read data to and from XML files to rebuild the 3D environment.

Now I'm trying to load a larger XML file, and an exception is raised during the generation of my 3D environment:

    [System out of memory exception]

I do not understand why, because after the exception is raised my file is not very heavy, it's about 80 mb. Is it normal to see an exception raise during the generation of an XML file up to 80 mb?

Development Environment used

  • Microsoft Windows 7 (x64) bits
  • Visual Studio 2013 professional Update 3
  • 16.0 GB (15.9GB usable) Ram
  • Intel i7 - 2670QM CPU @ 2.20GHz
  • Keep in mind, this is an 32bit application (XNA > 32bit)

I did do a test with ANTS memory profiler to check how the garbage collector works: Cant post image because of reputation...

Results indicate Class Vector3[] as the culprit:

Microsoft.Xna.Framework Vector3[] Grows form 0(bytes) to 305 218 872(bytes).

Code: Read the Xml file and load objects(basic-Model,-Mesh,-MeshPart) with properties into memory. This is needed to display models in 3D world.

Create a specialized Class that contains a object of type basic-model,-mesh,-meshPart. This class will contain extra info on the model,mesh,meshpart and have a link to the Database. I then load the new objects of the new class into 3 lists (model,mesh and meshPart list).

I then iterate through these lists through the entire project to do what is needed.

The problem comes in when:

  1. I added models.
  2. Saved to my xml file.
  3. Loading that file again!!!

So I assume the reading of the xml file is the problem...

or can it be that the lists with the objects gets too big??


Reading file:

 foreach (string directory in Directory.GetDirectories(tempPath))
    {
      string directoryName = Path.GetFileName(directory); //Get the directory name.

      if (directoryName == "Models") //If it is the Models directory name.
      {
        foreach (string filePath in Directory.GetFiles(directory))
        {
           if (Path.GetExtension(filePath) == ".xml") //If a .xml file.
           {
              Model_Data data = Model_Storage.Load(filePath);
              modelList.Add(data);
           }
        }
      }
    }



  public static Model_Data Load(string FilePath)
    {
       Model_Data data = Serialization.XNA_XML_Deserialize<Model_Data>(FilePath);
       data = XNB_Path_Load(data, FilePath);
       data = Texture_Custom_Load(data, FilePath);
       data = Linked_Files_Load(data, FilePath);
       return data;
    }

    public static T XNA_XML_Deserialize<T>(string LoadPath)
    {
        using (XmlReader reader = XmlReader.Create(LoadPath))
        {
            return IntermediateSerializer.Deserialize<T>(reader, null);
        }
    }

This is how the constructor of the specialized class looks for model:

public Spec_Model(Basic_Model _Model, int _ID_3Dem = -1)
{
   bModel = _Model; //object of basic-model 
   ID_3Dem = _ID_3Dem;
   Model_Vertices = Generate_Vertices();
   Model_Hash = Generate_Hash();
   State = ModelState.New;
}

Here I save the specialized class objects for future use:

FAC_Model fac_Model = new FAC_Model(Model, ID_3Dem);
lst_FAC_Models.Add(fac_Model);

foreach (Basic_Mesh Mesh in Model.Mesh_Collection)
{
   FAC_Mesh fac_Mesh = new FAC_Mesh(Mesh, Model.Unique_Identifier);
   lst_FAC_Mesh.Add(fac_Mesh);

   int meshPartCounter = 0;
   foreach (Basic_Mesh_Part_Properties Mesh_Part in Mesh.Properties.Mesh_Part_Properties)
   {
      meshPartCounter++;
      FAC_MeshPart fac_MeshPart = new FAC_MeshPart(Mesh_Part,Model.Unique_Identifier,Mesh.Properties.Unique_Identifier, meshPartCounter.AsStr());
      lst_FAC_MeshPart.Add(fac_MeshPart);
   }
}

No problems when loading a smaller xml file up 60mb.

In the file that I'm trying to load:

  • Models = 18
  • Meshes = +-3200
  • MeshParts = +- 4000

Any advice?

5
  • It can very well be that this error has nothing to do with your file, but with the memory used/required by your system.
    – Andrei V
    Oct 6, 2014 at 7:24
  • The exception occurs in this code: return IntermediateSerializer.Deserialize<T>(reader, null); Oct 6, 2014 at 9:42
  • What is Serialization.XNA_XML_Deserialize()? That's not part of XNA. "I've been developing a 3D viewer in XNA and Win-forms" - Also, unlike Managed DirectX, XNA can not be used with WinForms out of the box. If so, you should remove the XNA tag because what you have is perhaps no longer XNA
    – user585968
    Oct 6, 2014 at 9:52
  • Updated the post with the Serialization.XNA_XML_Deserialize() method. I am using my own XNA Library. The viewer is a Windows Forms application with an embedded XNA control. Oct 6, 2014 at 10:15
  • It seems that the objects (Class Vector3[]) never gets collected by the Garbage collector... The memory usage only grows. Tried forcing the GC with "GC.Collect()". It doesn't work. Any advise? Oct 8, 2014 at 9:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.