Method Dispose()

Asked

Viewed 527 times

6

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

In another event the div containing this listBox is hidden: display: none. To listBox which was filled previously continues to occupy the memory, does it not? It just does not appear on the screen because the div was hidden. The moment I hid the div it would be advisable to give a dispose() in the listBox since it is not being used (shown on the screen)? The listBox will only appear again if the user clicks the button that fires the event to fill it again.

  • In the first implementation of the record button click method we should have used the Dispose() connection method. With the use of instruction this is no longer necessary. Research about the purpose of the Dispose() method and why the using statement dispenses with the use of the same?

1 answer

7


The dispose() releases the object from memory, right?

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

To listBox which was filled previously continues to occupy the memory, is not?

Yes.

The moment I hide the div it would be advisable to give a dispose() in the listBox since the same is not being used (presented on the screen)?

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

Even if that were the case, the fact that you just hide the element has no reason to dismiss it.

But actually the problem is something else. You’re talking about a C#/resource. NET to apply to something that will effectively only run on the client (the browser). C# has no interference with what will run there. Even if it were possible to give one Dispose() would not affect the listbox in itself because it is not an element of the C# application but of the HTML/JS page. The ASP.ET class is only responsible for generating the HTML/JS text and managing the states it will receive from it, it is not the listbox even.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.