(Jan 7, 2019 06:34 PM)Neos07 Wrote: If you can show some code, I'd have the pleasure to help.
I made an example of a class with my attempt to collect but in debug i can not see the changes in heap,in order to not post on the forum too much unimportant code.
Code
public class test1
{
public string testtest;
}
public class TestClass : IDisposable
{
private List<string> _collection;
private test1 _test1;
private test1 _test2;
private bool _disposed = false;
public string ReturnString()
{
return "some string";
}
#region Implementacion of IDisposable
public void Dispose()
{
if (!_disposed)
{
_disposed = true;
Dispose(true);
GC.SuppressFinalize(this);
}
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
instance = null;
}
}
#endregion
#region Singleton pattern
private static TestClass instance;
private TestClass()
{
_collection = new List<string>();
_test1 = new test1();
_test2 = new test1();
}
public static TestClass Shared()
{
if (instance == null)
instance = new TestClass();
return instance;
}
#endregion
~TestClass()
{
Debug.WriteLine("FINALIZE");
if (!_disposed)
{
_disposed = true;
Dispose(false);
}
}
}
Solution for now, not what I wanted but it will help until I find a better solution.i make class as facade to get the opportunity to do cleaning on the parts where I need it.
Code
public class TestFacade
{
public string ReturnString()
{
using (var sing = TestClass.Shared())
{
return sing.ReturnString();
}
}
public static TestFacade Instance { get; } = new TestFacade();
}