Raised This Month: $51 Target: $400
 12% 

When should I be using "delete" on variables?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gromit190
Junior Member
Join Date: Jun 2019
Old 08-27-2021 , 08:57   When should I be using "delete" on variables?
Reply With Quote #1

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?
gromit190 is offline
dustinandband
Senior Member
Join Date: May 2015
Old 08-27-2021 , 22:24   Re: When should I be using "delete" on variables?
Reply With Quote #2

From the SM discord
https://i.imgur.com/Lg32rHI.png
dustinandband is offline
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 08-28-2021 , 11:10   Re: When should I be using "delete" on variables?
Reply With Quote #3

Quote:
Originally Posted by dustinandband View Post
hey, thats me !

Quote:
Originally Posted by gromit190 View Post
But is this the only use for the "delete" statement?
basically, yes
__________________
kratoss1812 is offline
gromit190
Junior Member
Join Date: Jun 2019
Old 08-30-2021 , 09:22   Re: When should I be using "delete" on variables?
Reply With Quote #4

Quote:
Originally Posted by kratoss1812 View Post
basically, yes
Ok, thanks!
gromit190 is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 09-10-2021 , 08:34   Re: When should I be using "delete" on variables?
Reply With Quote #5

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
__________________
GitHub | Discord: @azalty | Steam

Last edited by azalty; 09-10-2021 at 08:35.
azalty is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:21.


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