static List <MemoryProblem> Flush() { var problems = new List <MemoryProblem>(); lock (_memory) { var frees = new List <Block>(); foreach (var item in _memory) { var block = item.Value; if (block.skip) { continue; } if (block.count == 0) { block.skip = true; } if (block.count > 0) { frees.Add(block); } if (block.count == 0 || block.count > 1) { var problem = new MemoryProblem { Type = block.count == 0 ? MemoryProblemType.Leaked : MemoryProblemType.MultipleFree, Size = block.bytes, FreeCount = block.count, StackTrace = block.stack, File = block.file, Line = block.line, }; Console.WriteLine(problem); problems.Add(problem); } } foreach (var block in frees) { Marshal.FreeHGlobal(block.ptr); _memory.Remove(block.ptr); } } return(problems); }
static List<MemoryProblem> Flush() { var problems = new List<MemoryProblem>(); lock (_memory) { var frees = new List<Block>(); foreach (var item in _memory) { var block = item.Value; if (block.skip) continue; if (block.count == 0) block.skip = true; if (block.count > 0) frees.Add(block); if (block.count == 0 || block.count > 1) { var problem = new MemoryProblem { Type = block.count == 0 ? MemoryProblemType.Leaked : MemoryProblemType.MultipleFree, Size = block.bytes, FreeCount = block.count, StackTrace = block.stack, File = block.file, Line = block.line, }; Console.WriteLine(problem); problems.Add(problem); } } foreach (var block in frees) { Marshal.FreeHGlobal(block.ptr); _memory.Remove(block.ptr); } } return problems; }