Memory Leaks
This commit is contained in:
@@ -54,6 +54,8 @@ namespace DynamORM.Helpers.Dynamics
|
||||
[Serializable]
|
||||
public class Node : IDynamicMetaObjectProvider, IExtendedDisposable, ISerializable
|
||||
{
|
||||
private DynamicParser _parser = null;
|
||||
|
||||
#region MetaNode
|
||||
|
||||
/// <summary>
|
||||
@@ -763,6 +765,23 @@ namespace DynamORM.Helpers.Dynamics
|
||||
|
||||
return string.Format("({0} {1} {2})", Host.Sketch(), Operation, Right.Sketch());
|
||||
}
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
|
||||
if (Right != null && Right is Node)
|
||||
{
|
||||
Node n = (Node)Right;
|
||||
|
||||
if (!n.IsDisposed)
|
||||
n.Dispose();
|
||||
|
||||
Right = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Binary
|
||||
@@ -889,7 +908,16 @@ namespace DynamORM.Helpers.Dynamics
|
||||
public Node Host { get; internal set; }
|
||||
|
||||
/// <summary>Gets reference to the parser.</summary>
|
||||
public DynamicParser Parser { get; internal set; }
|
||||
public DynamicParser Parser
|
||||
{
|
||||
get { return _parser; }
|
||||
internal set
|
||||
{
|
||||
_parser = value;
|
||||
if (_parser != null)
|
||||
_parser._allNodes.Add(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Node"/> class.
|
||||
@@ -982,12 +1010,18 @@ namespace DynamORM.Helpers.Dynamics
|
||||
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public virtual void Dispose()
|
||||
{
|
||||
IsDisposed = true;
|
||||
|
||||
if (Host != null && !Host.IsDisposed)
|
||||
Host.Dispose();
|
||||
|
||||
Host = null;
|
||||
|
||||
Parser = null;
|
||||
}
|
||||
|
||||
#endregion Implementation of IExtendedDisposable
|
||||
@@ -1017,6 +1051,7 @@ namespace DynamORM.Helpers.Dynamics
|
||||
#region Data
|
||||
|
||||
private List<Node.Argument> _arguments = new List<Node.Argument>();
|
||||
private List<Node> _allNodes = new List<Node>();
|
||||
private object _uncertainResult;
|
||||
|
||||
#endregion Data
|
||||
@@ -1129,6 +1164,34 @@ namespace DynamORM.Helpers.Dynamics
|
||||
public void Dispose()
|
||||
{
|
||||
IsDisposed = true;
|
||||
|
||||
if (_uncertainResult != null && _uncertainResult is Node)
|
||||
{
|
||||
((Node)_uncertainResult).Dispose();
|
||||
_uncertainResult = null;
|
||||
}
|
||||
|
||||
if (Last != null && !Last.IsDisposed)
|
||||
{
|
||||
Last.Dispose();
|
||||
Last = null;
|
||||
}
|
||||
|
||||
if (_arguments != null)
|
||||
{
|
||||
_arguments.ForEach(x => { if (!x.IsDisposed) x.Dispose(); });
|
||||
|
||||
_arguments.Clear();
|
||||
_arguments = null;
|
||||
}
|
||||
|
||||
if (_allNodes != null)
|
||||
{
|
||||
_allNodes.ForEach(x => { if (!x.IsDisposed) x.Dispose(); });
|
||||
|
||||
_allNodes.Clear();
|
||||
_allNodes = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Implementation of IExtendedDisposable
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace DynamORM.Helpers.Dynamics
|
||||
/// <summary>Class that allows to use interfaces as dynamic objects.</summary>
|
||||
/// <typeparam name="T">Type of class to proxy.</typeparam>
|
||||
/// <remarks>This is temporary solution. Which allows to use builders as a dynamic type.</remarks>
|
||||
public class DynamicProxy<T> : DynamicObject
|
||||
public class DynamicProxy<T> : DynamicObject, IDisposable
|
||||
{
|
||||
private T _proxy;
|
||||
private Type _type;
|
||||
@@ -59,15 +59,15 @@ namespace DynamORM.Helpers.Dynamics
|
||||
_proxy = proxiedObject;
|
||||
_type = typeof(T);
|
||||
|
||||
var members = GetAllMembers(_type);
|
||||
var mapper = Mapper.DynamicMapperCache.GetMapper<T>();
|
||||
|
||||
_properties = members
|
||||
.Where(x => x is PropertyInfo)
|
||||
_properties = mapper
|
||||
.ColumnsMap
|
||||
.ToDictionary(
|
||||
k => k.Name,
|
||||
v => new DynamicPropertyInvoker((PropertyInfo)v, null));
|
||||
k => k.Value.Name,
|
||||
v => v.Value);
|
||||
|
||||
_methods = members
|
||||
_methods = GetAllMembers(_type)
|
||||
.Where(x => x is MethodInfo)
|
||||
.Cast<MethodInfo>()
|
||||
.Where(m => !((m.Name.StartsWith("set_") && m.ReturnType == typeof(void)) || m.Name.StartsWith("get_")))
|
||||
@@ -312,5 +312,21 @@ namespace DynamORM.Helpers.Dynamics
|
||||
|
||||
return type.GetMembers(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance);
|
||||
}
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
object res;
|
||||
TryInvokeMethod("Dispose", out res, new object[] { });
|
||||
|
||||
_methods.Clear();
|
||||
_properties.Clear();
|
||||
|
||||
_methods = null;
|
||||
_properties = null;
|
||||
_type = null;
|
||||
_proxy = default(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user