OSDN Git Service

Potential fix for Memory leak - Clear (some) Metadata post persist
[automap/automap.git] / Automap / Subsystems / AutomapSystem.cs
index 8cbfc20..880fe90 100644 (file)
@@ -53,7 +53,7 @@ namespace Automap
 
                internal CommandType CurrentState { get; set; }
                //Run status, Chunks processed, stats, center of map....
-               private uint nullChunkCount, updatedChunksTotal;
+               private uint nullChunkCount, nullMapCount, updatedChunksTotal;
                private Vec2i startChunkColumn;
 
                private readonly int chunkSize;
@@ -184,7 +184,7 @@ namespace Automap
                                                if (mapChunk == null)
                                                {
                                                        Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key);
-                                                       nullChunkCount++;
+                                                       nullMapCount++;
                                                        columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
                                                        continue;
                                                }
@@ -219,8 +219,9 @@ namespace Automap
                                                        columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem);
                                                        Logger.VerboseDebug("Un-painted chunk: ({0}) ", mostActiveCol.Key);
                                                }
-
                                        }
+                               //Cleanup persisted Metadata...
+                               chunkTopMetadata.ClearMetadata( );
                                }
 
                                UpdateStatus(this.updatedChunksTotal, this.nullChunkCount, updatedChunks);
@@ -500,6 +501,7 @@ namespace Automap
                        #if DEBUG
                        Logger.VerboseDebug("Chunk null or empty X{0} Y{1} Z{2}", key.X, targetChunkY, key.Y);
                        #endif
+                       nullChunkCount++;
                        continue;
                        }
 
@@ -512,14 +514,12 @@ namespace Automap
 
                                        foreach (var blockEnt in chunkData.BlockEntities)
                                        {
-
                                                if (blockEnt != null && blockEnt.Block != null && BlockID_Designators.ContainsKey(blockEnt.Block.BlockId))
                                                {
                                                        var designator = BlockID_Designators[blockEnt.Block.BlockId];
                                                        designator.SpecialAction(ClientAPI, POIs, blockEnt.Pos.Copy(), blockEnt.Block);
                                                }
                                        }
-
                                }
                                /********************* Chunk/Column BLOCKs scanning ****************/
                                //Heightmap, Stats, block tally
@@ -528,6 +528,10 @@ namespace Automap
                                int X_index, Y_index, Z_index;
                                X_index = Y_index = Z_index = 0;
 
+                               //Ensure ChunkData Metadata fields arn't null...due to being tossed out
+                               if (chunkMeta.HeightMap == null) { chunkMeta.HeightMap = new ushort[chunkSize, chunkSize]; }
+                               if (chunkMeta.RockRatio == null) { chunkMeta.RockRatio = new Dictionary<int, uint>(10); }
+
                                do
                                {
                                        do