AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   When should I be using "delete" on variables? (https://forums.alliedmods.net/showthread.php?t=334079)

gromit190 08-27-2021 08:57

When should I be using "delete" on variables?
 
The wiki page about Handles clearly say that all handles should (must) be closed after use, as they reserve memory which should be freed. That's good to know.

But is this the only use for the "delete" statement? Are there no other situations in sourcepawn scripting where memory needs to be "manually" freed?

dustinandband 08-27-2021 22:24

Re: When should I be using "delete" on variables?
 
From the SM discord
https://i.imgur.com/Lg32rHI.png

kratoss1812 08-28-2021 11:10

Re: When should I be using "delete" on variables?
 
Quote:

Originally Posted by dustinandband (Post 2756344)

hey, thats me !

Quote:

Originally Posted by gromit190 (Post 2756298)
But is this the only use for the "delete" statement?

basically, yes

gromit190 08-30-2021 09:22

Re: When should I be using "delete" on variables?
 
Quote:

Originally Posted by kratoss1812 (Post 2756370)
basically, yes

Ok, thanks!

azalty 09-10-2021 08:34

Re: When should I be using "delete" on variables?
 
Some handles are automatically closed. When it's the case, it'll be mentionned.

Note though that handles that are automatically close will still have their reference (idk if it's the right term, I'll just call it like that)! A timer handle will be closed when you return Plugin_Stop in its function, but it won't set the variable value to null, so remember to do that (if you keep the Handle after the function is finished, ex: a global Handle for a timer)!

Ex:
Hander timerHandle = (reference)
CloseHandle(timerHandle) removes the handle (pointed by the reference), but timerHandle is still equal to (reference), but this reference points to nothing, so you should always set it to null if you saved the Handle in a global variable!

If you have any question, special case, or error, just ask :)


All times are GMT -4. The time now is 05:00.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.