Browse Source

dispose unneeded AXml data after parsing files without IViewContent

pull/14/head
Siegfried Pammer 15 years ago
parent
commit
85715b044d
  1. 15
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs
  2. 28
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlParser.cs

15
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs

@ -104,6 +104,21 @@ namespace ICSharpCode.XamlBinding @@ -104,6 +104,21 @@ namespace ICSharpCode.XamlBinding
return visitor.CompilationUnit;
}
//}
// During project load all XAML files are parsed
// most of them are not opened, thus fileContent.Version is null.
// We can clear the parser data, because the file will be reparsed
// as soon as it is opened by the user.
// This will save us some memory, because we only use the
// compilation unit created by the visitor above for code completion.
if (fileContent.Version == null) {
parser.Lock.EnterWriteLock();
// double-checked locking (other threads might parse the document in the meantime)
if (lastParsedVersion == null) {
parser.Clear();
}
parser.Lock.ExitWriteLock();
}
}
/// <summary>

28
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlParser.cs

@ -97,15 +97,8 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -97,15 +97,8 @@ namespace ICSharpCode.AvalonEdit.Xml
/// <summary> Create new parser </summary>
public AXmlParser()
{
this.UnknownEntityReferenceIsError = true;
this.TrackedSegments = new TrackedSegmentCollection();
this.Lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
this.userDocument = new AXmlDocument() { Parser = this };
this.userDocument.Document = this.userDocument;
// Track the document
this.TrackedSegments.AddParsedObject(this.userDocument, null);
this.userDocument.IsCached = false;
ClearInternal();
}
/// <summary> Throws exception if condition is false </summary>
@ -181,5 +174,24 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -181,5 +174,24 @@ namespace ICSharpCode.AvalonEdit.Xml
return userDocument;
}
}
public void Clear()
{
if (!Lock.IsWriteLockHeld)
throw new InvalidOperationException("Write lock needed!");
ClearInternal();
}
void ClearInternal()
{
this.UnknownEntityReferenceIsError = true;
this.TrackedSegments = new TrackedSegmentCollection();
this.userDocument = new AXmlDocument() { Parser = this };
this.userDocument.Document = this.userDocument;
// Track the document
this.TrackedSegments.AddParsedObject(this.userDocument, null);
this.userDocument.IsCached = false;
}
}
}

Loading…
Cancel
Save