Dispose () method

3

dispose() frees the object from memory, right? I do not know when it is necessary to use it. For example, I have a page, on this page there is listBox com visible = "false" , in an event this listBox becomes true .

In another event the div that contains this listBox is hidden: display: none . The% w / o% that was previously filled still occupies memory, right? It just does not appear on the screen because the listBox has been hidden. When I hide div would it be advisable to give div to dispose() since it is not being used (shown on the screen)? The listBox will only appear again if the user clicks the button that triggers the event to fill it again.

    
asked by anonymous 23.12.2016 / 14:00

1 answer

7
  

Dispose () frees the object from memory, right?

No. Only the garbage collector does this. What it does is release unmanaged, external resources to the application. Eventually they may occupy some unmanaged memory, but that's not your problem, you release the feature.

  

The listbox that was previously filled still occupies memory, does not it?

Yes.

  

When I hide the div, it would be advisable to give a dispose () in the listBox since it is not being used (displayed on the screen)?

No. Because this is not an "expendable" resource (see its documentation and the IDisposable interface is not implemented). I could not even want it.

Even though it was the case, the fact that you just hide the element did not have it because you should dispense it.

But in fact the problem is another. You're talking about a C # / .Net resource to apply to something that will actually only run on the client (the browser). C # does not have any interference in what will run there. Even if it were possible to give Dispose() to this object, it would not affect the listbox itself because it is not an element of the C # application but rather the HTML / JS page. The ASP.Net class is only responsible for generating HTML / JS text and managing the states it will receive from it, it is not the listbox .

23.12.2016 / 14:13