View Single Post
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 02-06-2024 , 18:01   Re: Clear() does not free the ArrayList memory in sourcemod?
Reply With Quote #8

Quote:
Originally Posted by Earendil View Post

All those things you are mentioning are Objects, once initialized with "new" a memory space is asigned to the object, using clear() will not free that memory space since objects still exist even if its content is removed.

Using delete causes to remove the assigned memory space, freeing it, but at a cost that you are required to initialize them again.

If you need to empty/fill an ArrayList multiple times, is better to use clear because is faster to skip the memory assignment. In the other hand is better to destroy objects and then initialize them if the data they are storing is big enough and is not required again.

Since SP has no garbage collector, allways delete handles once you don't need to use them anymore and always delete handles once you ended them in a code block. If not you will have memory leaks that will only be cleared after plugin unload.

And yeah, SourcePawn is not Object Oriented, but I imagine the lower layers of SM will work with objects, and ArrayLists and the other things are basically SM objects that we access via Handles.
Thank you, good to know, I will be more careful in the future.
__________________

Last edited by HarryPotter; 02-06-2024 at 18:02.
HarryPotter is offline