This project has moved. For the latest updates, please go here.

Memory release of KmlFile and Kml class

Jan 31, 2016 at 10:07 PM
Edited Jan 31, 2016 at 10:08 PM
I have tried to load two kml files one by one, but after using the first one, I don't know how to close it. So when the second one is loaded, it crashed with the notification of memory lacking. I suppose the reason is kmlFile and kml haven't released any memory, how to release the memory from kmlFile or kml after using? kmlFile and kml don't have the release function such as dispose(), so it's not easy to do that.

ArrayList kml_file_name = new ArrayList();
kml_file_name.Add(@"doc1.kml");// 122,677 KB
kml_file_name.Add(@"doc2.kml");// 128,002 KB
KmlFile kmlfile;
Kml kml;

for (int i = 0; i < kml_file_name.Count; i++)
{
    using (FileStream kmlstream = File.Open(kml_file_name[i].ToString(), FileMode.Open)
    {
            kmlfile = null;
            kml = null;
            GC.Collect();//It doesn't work somehow.

            kmlfile = KmlFile.Load(kmlstream);
            kml = kmlfile.Root as Kml;

            if (kml != null)
            {
                 foreach (var placemark in kml.Flatten().OfType<Placemark>())
                  {
                       if (placemark.Name == "expected_id")
                        {
                                    //do something
                        }
                   }
             }
     }
}