Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

destruction of a variable or array in C#

I have a variable or array, which I no longer needed. How to destroy them? Sorry for noob-question.

like image 959
Alexry Avatar asked Apr 28 '10 07:04

Alexry


People also ask

Can array be static in C?

If the array has static storage duration (meaning it was declared at file scope outside of any function body, or was declared with the static keyword) and no initializer is present, then all of the array elements are initialized to 0 (for scalars) or NULL (for pointers).

Which variables are destroyed when you exit the function?

The return statement should not return a pointer that has the address of a local variable ( sum ) because, as soon as the function exits, all local variables are destroyed and your pointer will be pointing to someplace in the memory that you no longer own.

Do local variables get destroyed?

If a function is called more than once in a program, the values stored in the function's local variables do not persist between function calls. This is because the local variables are destroyed when the function terminates, and are then re-created when the function starts again.

Can you have an array of void in C?

In C, it is possible to have array of all types except following. 1) void. 2) functions. But we can have array of void pointers and function pointers.


1 Answers

You don't. Just let the reference go out of scope and it'll be automatically garbage-collected.

like image 136
Dean Harding Avatar answered Sep 26 '22 06:09

Dean Harding