diff options
author | Jb Evain <jbevain@gmail.com> | 2011-10-27 16:53:07 +0400 |
---|---|---|
committer | Jb Evain <jbevain@gmail.com> | 2011-10-27 16:53:07 +0400 |
commit | 8771de6415d3fa5e34b12fd90519a5405c02e8b2 (patch) | |
tree | 0a1707ab3fc77c49d3f5f6f51628089ccffb1d19 /Mono.Cecil/ModuleDefinition.cs | |
parent | ecdd7454b53a4d6b57c9eb2a500b91025a63b401 (diff) |
First pass at a branch with reduced memory usage; Keeps an open handle on the file, dispose your modules
Diffstat (limited to 'Mono.Cecil/ModuleDefinition.cs')
-rw-r--r-- | Mono.Cecil/ModuleDefinition.cs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Mono.Cecil/ModuleDefinition.cs b/Mono.Cecil/ModuleDefinition.cs index 0d137e0..4e4ef37 100644 --- a/Mono.Cecil/ModuleDefinition.cs +++ b/Mono.Cecil/ModuleDefinition.cs @@ -189,7 +189,7 @@ namespace Mono.Cecil { #endif - public sealed class ModuleDefinition : ModuleReference, ICustomAttributeProvider { + public sealed class ModuleDefinition : ModuleReference, ICustomAttributeProvider, IDisposable { internal Image Image; internal MetadataSystem MetadataSystem; @@ -439,11 +439,17 @@ namespace Mono.Cecil { this.runtime = image.Runtime; this.architecture = image.Architecture; this.attributes = image.Attributes; - this.fq_name = image.FileName; + this.fq_name = image.Stream.GetFullyQualifiedName (); this.reader = new MetadataReader (this); } + public void Dispose () + { + if (Image != null) + Image.Dispose (); + } + public bool HasTypeReference (string fullName) { return HasTypeReference (string.Empty, fullName); @@ -915,9 +921,7 @@ namespace Mono.Cecil { public static ModuleDefinition ReadModule (string fileName, ReaderParameters parameters) { - using (var stream = GetFileStream (fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { - return ReadModule (stream, parameters); - } + return ReadModule (GetFileStream (fileName, FileMode.Open, FileAccess.Read, FileShare.Read), parameters); } static void CheckStream (object stream) |