示例#1
0
        public void NonPrimitive()
        {
            const int size  = 10000;
            const int loop  = 100000;
            var       first = GetCurrentMemory();

            // Avoid effect of StdVectorElementTypesRepository
            var tmp = new StdVector <StdString>();

            tmp.Dispose();

            var start  = GetCurrentMemory() - first;
            var source = Enumerable.Range(0, size).Select(i => new StdString(i.ToString())).ToArray();

            for (var count = 0; count < loop; count++)
            {
                var vector = new StdVector <StdString>(source);
                vector.Dispose();
            }

            source.DisposeElement();

            // Important!!
            GC.Collect(2, GCCollectionMode.Forced, true);

            var end = GetCurrentMemory() - first;

            Console.WriteLine("        Start Total Memory = {0} KB", start / 1024);
            Console.WriteLine("          End Total Memory = {0} KB", end / 1024);
            Console.WriteLine("Delta (End - Start) Memory = {0} KB", (end - start) / 1024);

            // Rough estimate whether occur memory leak (less than 10240KB)
            Assert.IsTrue((end - start) / 1024 < 10240);
        }
示例#2
0
 // method disposes data that was used during processing
 // call after we're done using the keypoint data
 public override void DisposeData()
 {
     // check if objects exist and aren't disposed already
     // if so, dispose them
     if (datumProcessed != null && !datumProcessed.IsDisposed)
     {
         datumProcessed.Dispose();
     }
     if (data != null && !data.IsDisposed)
     {
         data.Dispose();
     }
 }