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

ADT Arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
blaacky
Senior Member
Join Date: Oct 2012
Old 02-02-2014 , 19:03   ADT Arrays
Reply With Quote #1

PHP Code:
#include <sourcemod>

new    Handle:g_Array;

public 
OnPluginStart()
{
    
g_Array CreateArray();
    
    for(new 
i=010000i++)
    {
        
PushArrayCell(g_Arrayi);
    }
    
    
g_Array CreateArray();

Would this cause memory leaks? If so, what is a good way to avoid it?
__________________

Last edited by blaacky; 02-02-2014 at 19:06.
blaacky is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-02-2014 , 19:51   Re: ADT Arrays
Reply With Quote #2

Yes. Because you haven't closed the first array handle, that Handle (and its contents) have been leaked.

Either use ClearArray instead of CreateArray for the second one or CloseHandle g_Array first.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 02-02-2014 at 19:52.
Powerlord is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 02-02-2014 , 22:15   Re: ADT Arrays
Reply With Quote #3

You could copies the handle lf the first array flr safe keeping, and close it later :/
Handle2 = Createarray()
Handle1 = Handle2
Handle2 = Createarray()
?
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 02-03-2014 , 07:15   Re: ADT Arrays
Reply With Quote #4

Quote:
Originally Posted by friagram View Post
Handle1 = Handle2
Shouldn't you use CloneHandle for something like that?
Marcus_Brown001 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 02-03-2014 , 09:29   Re: ADT Arrays
Reply With Quote #5

Quote:
Originally Posted by Marcus_Brown001 View Post
Shouldn't you use CloneHandle for something like that?
Because it's exactly that. you would be cloning the handle. Which would assign a new handle to that variable. Although i cant seem to think of a senario where you would create an array, and then assign it to another variable then create another with the old variable.. If you make anything with handles just close it when you're done with it. or if it's a keyvalue then cache it in variables. No need in keeping a handle open. (Sometimes menus will be a handle you don't want to close.) Sometimes closing menu handles while the menu is still open on a client it can lead to a server crash.
Mitchell is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-03-2014 , 10:40   Re: ADT Arrays
Reply With Quote #6

Quote:
Originally Posted by Mitchell View Post
Sometimes closing menu handles while the menu is still open on a client it can lead to a server crash.
Which is why you don't close Menu handles anywhere but a MenuAction_End callback (which is why it exists...).
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 02-03-2014 , 14:46   Re: ADT Arrays
Reply With Quote #7

Quote:
Originally Posted by Powerlord View Post
Which is why you don't close Menu handles anywhere but a MenuAction_End callback (which is why it exists...).
I think my Ross was correct..
It depend on what the "handel" store callback..
If it as simple as timer, it just give you the two active function which is double the callback like double the timer function..

but if the handle store harm function.. it does crash the server on the second frame..
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.
GsiX is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 02-04-2014 , 01:37   Re: ADT Arrays
Reply With Quote #8

Quote:
Originally Posted by Mitchell View Post
Because it's exactly that. you would be cloning the handle. Which would assign a new handle to that variable. Although i cant seem to think of a senario where you would create an array, and then assign it to another variable then create another with the old variable.. If you make anything with handles just close it when you're done with it. or if it's a keyvalue then cache it in variables. No need in keeping a handle open. (Sometimes menus will be a handle you don't want to close.) Sometimes closing menu handles while the menu is still open on a client it can lead to a server crash.
You might use something like this if you are using an array of arrays, and you have to pass an array through some function,

Dunno, mabye the func could close the handle, at which point you could like... If findvalueinarray return value, removefromarray (because it was closed). Normally youd must pass the array, but if you had multiples, i suppose this could work. Dunno, haven't had this happen.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram 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 02:50.


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