Jump to content

Unset, destroy variable, clear array


laurin1
 Share

Recommended Posts

ummm u dont have to clear them you can just set them to something else and it will overwrite it

$variable = 5
MsgBox(0,"variable",$variable)
$variable = 130
MsgBox(0,"variable",$variable)

I understand that. However, there are times when I want to make sure the variable is cleared, especially with arrays. From my tests, it appears even arrays can be cleared by setting them $array = ''; but I want to make sure.

Keith Davis

MCSA, ZCE, A+, N+

http://www.laurinkeithdavis.com

Link to comment
Share on other sites

  • 8 years later...

This is not enought. If you have custom functions with local arrays you dare to get trash from it.

This is the case in the usefull Call() calls, with a array as argument and 'CallArgArray' in array[0]. You will get all wrong.

Is needed wipe manually, example:

Func __CustomCall($sCadenaLlamada)
;[....]
Local $aArgvs=StringSplit($sArgvs,',',1)
Local $coder=$aArgvs[0]
$aArgvs[0]='CallArgArray'
$CallReturn=Call($sFuncName,$aArgvs)
For $i=0 To $coder ; Wipe Array
 $aArgvs[$i]=Null
Next
If @error=0xDEAD Or @extended=0xBEEF Then
 $coder=0
Else
 $coder=$CallReturn
EndIf
;[....]
Return($coder)

 

Edited by zalomalo

My english shucks, i know it.

Link to comment
Share on other sites

If you want to destroy you array, just set you array variable to 0 :

$aArray = 0

Edit :

Also, you can read the Keyword Dim / Global / Local / Const page in the helpfile :

To erase an array (maybe because it is a large global array and you want to free the memory), simply assign a single value to it:
$aArray = 0
This will free the array and convert it back to the single value of 0

Edited by jguinch
Link to comment
Share on other sites

Necroing an 8 1/2 year old thread isn't a record, but it's close.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Sorry a lot, i didnt realise was so old post. Sorry.

But, jguinch is wrong. Is not enough, i have read the documentation and done 1000 test.

Tell me if you are interested in discuss this issue.

Cheers.

Edited by zalomalo

My english shucks, i know it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...