Note that there are some explanatory texts on larger screens.

plurals
  1. PObreaking references to a form C#
    primarykey
    data
    text
    <p>I have a license project (Database Interaction Project) and I want to remove all references from a form that loads data from a DB, because I load a lot of data and the memory usage is high. I profiled the application (.Net Memory Profiler, Ants) and got the references that are connected to that form: </p> <p><code>Module1.cs / Class1 -&gt; Module2.cs / Class2 with the reference ref 1 written on the arrow</code></p> <p>I must remove them without drastic changes, and the program should still work :). If I put the references to null the program crashes because it might need those refs again The trouble is, I think, that the reference showed can be declared in different modules than the ones showed by the Profiler, making it harder to follow.</p> <p>In the Data.cs i have the <code>Data</code> class and in it I declare</p> <pre><code>mVController = table.Resolve&lt;ImVController&gt;(); </code></pre> <p><code>mVController</code> - is of Type <code>ImVController</code> (doesn't matter the name) <code>table</code> - is of type <code>IUnityController</code> <code>ImVController</code> - is the interface where <code>mVController</code> is declared <code>Resolve</code> - makes container of the same type with mVController</p> <p>I want to know if i put <code>mVController = null</code> when no longer needed will the GC enter / object will be eligible for collection? </p> <p>or the <code>table</code> will have hold the reference to the object of type <code>ImVController</code>? My guess it that it will be eligible.</p> <p>what if some object is declared:</p> <p><code>object newObject = DomainObjectFactory.GetObject(typeOfObject);</code></p> <p>then it uses mVController:</p> <p><code>(newObject as Class1).MethodFromClass1(mVController.Property1, mVController.Property2, ...);</code></p> <p>do I get rid of the reference like this:</p> <p><code>object = null;</code> then it will be collected at a certain time?</p> <p>another question: should the references be passed with ref in a method (e.g. <code>public void method(ref Type obj)</code> then make obj = null; in the method so that the object is null also? Will all refs from all the project point to null> so the GC could collect? and then call the method also with ref: <code>method (ref obj)</code> when the object is no longer needed and should go out of scope? </p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload