Unsetting a variable?

Just starting out? Need help? Post your questions and find answers here.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Unsetting a variable?

Post by Mistrel »

Is there a way to "unset" a variable similar to php's unset()?
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

no you can't (as far as i know).

local vars (in procedures) are automatically unset when exiting the proc.

others vars are unset when exiting the app.

the only thing you can do is to 'nullify' your var ( myvar = #Null, myvar$ = #Null$ ) but it's not an 'unset'.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

A workaround would be adding your variables to a linked list.
But that would add a lot of cpu and memory overhead so its only usefull if you have a lot of dynamic memory assignment going on.

In most cases its a waste of resources thougth.
JonChaos
User
User
Posts: 26
Joined: Wed Nov 03, 2004 11:23 pm

Post by JonChaos »

Another option would be allocating memory with AllocateMemory(Size) and work with Peek / Poke.
If the memory isnt used anymore you could free it with FreeMemory(*MemoryID) .
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

People ignore the main question: why would you want to do such a thing?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply