Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete or reinitialize a 'new' variable?

Before you report me for asking a commonly-asked question, hear me out.

I am writing a program to read from a datalogger using C# and windows forms. Each of the channels can mean different things, such as lift, drag, and pressure. I plan to make these channels configurable. Here is how such a channel is initialized:

private Channel Lift_Channel = new Channel(1);

This initializes Lift_Channel as a Channel object that references channel 1 on the logger.

However, the constructor method Channel(int) is the only method I can use to set the channel. If I want Lift_Channel to point to channel 2, I would like to do something like this.

delete Lift_Channel;
Lift_Channel = new Channel(2);

I feel like if I can't delete Lift_Channel then recreate it, I will have memory leak errors because the Channel(1) data will be floating around.

Any ideas?

like image 629
user2596874 Avatar asked Apr 15 '15 00:04

user2596874


People also ask

How do you delete a created variable?

Variables which have been created in Q as copies of other variables, or as formulas or filters, can be deleted by right-clicking them in the Variables and Questions tab and selecting Delete Copied or Constructed Variables.

How do you unassign a variable in Python?

to clear Variables in Python just use %reset-f. You can clear variables in python by using %reset-f function. If you want to delete any specific variable then use %reset-f. %reset-f Use it t delete the variables.

How do you delete a variable in Python?

Delete a variable You can also delete Python variables using the command del “variable name”. In the below example of Python delete variable, we deleted variable f, and when we proceed to print it, we get error “variable name is not defined” which means you have deleted the variable.


1 Answers

Nope, nothing to delete. After you re-assign it, Lift_Channel will no longer point to the old memory address, and the memory will be cleaned up.

like image 175
Rufus L Avatar answered Sep 24 '22 19:09

Rufus L