Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's nothing really wrong with portion of your code shown above. Just understanding is required about how it works.</p> <p><code>Session.Remove(key)</code> removes memory used for the key in the session dictionary. When using second approach of : <code>Session["searchCase"]=null;</code> , the key will still exist in the Session although the value is null.</p> <p>Try setting the <code>Session["Key_Name"]</code> to <code>null</code>. For example: </p> <pre><code>if (Session["CaseNumber"] != "" || Session["CaseNumber"] != null) { casenumber = Session["CaseNumber"].ToString(); guid = Session["guid"].ToString(); _duration = bal.viewServiceActivity(guid); case1 = bal.viewCaseDetail(casenumber); dt = bal.getRelatedNotes(guid); Session["CaseNumber"] = null; // Set NULL Session["guid"] = null; // Set NULL } </code></pre> <p><strong><code>Session.Remove()</code> doesn't destroys the object bypassing all basic .net rules of object referencing and memory management.</strong> What you need to understand here is that <code>Session.Remove()</code> does exactly what it suggests: It removes the reference to the object from its internal collection. Nothing more to expect.</p> <p>If you need something destroyed, you need to implement <code>IDisposable</code>, and furthermore, you may instruct the garbage collector to collect if you are in a hurry using <code>GC.Collect()</code>.</p> <p>Check this SO question: <a href="https://stackoverflow.com/questions/538060/proper-use-of-the-idisposable-interface">Proper use of the IDisposable interface</a> </p> <p><a href="http://social.microsoft.com/Forums/en-US/abb22957-2ec4-4ef5-b6a2-4e3f3301d9fc/sessionremovekey-doesnt-actually-work" rel="nofollow noreferrer">Microsoft Forum</a> confirms the same. </p> <p>It seems more like an optimization OR so called standard way of implementation. When you remove an object it is 'marked for removal' but not really removed...unless space is required. It's how garbage collection works. Just because an object goes out of scope doesn't mean it's destructor gets called and the memory freed immediately. May be <code>GC</code> can remove an object much later.</p> <p><strong>Still, as a last check, do this</strong> :</p> <p>Make sure you are not viewing a cached version of the page, or you don't add the item to the Session object again somewhere in your application.</p>
    singulars
    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. VO
      singulars
      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