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

Handles not closing!!!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
Old 08-03-2010 , 20:49   Handles not closing!!!
Reply With Quote #1

Every 20 minutes or so after my plugin starts, it unloads itself from having too many open handles. (16000 something). What I don't get is why there are so many. After every handle I declare in the code, I close it, or at least I think I do.

Code:
stock ExitHandle(&Handle:ToClose)
{
	if(ToClose != INVALID_HANDLE)
    	{
        	CloseHandle(ToClose);
    	}

	ToClose = INVALID_HANDLE;
}
This returns no errors, so I guess it's doing it's job. The only handles that aren't being closed I suppose are timers. So I guess my question is, how do you close timer handles once they are finished?
__________________
almcaeobtac is offline
DarkEnergy
SourceMod Donor
Join Date: Apr 2008
Location: Georgia Tech, MSECE
Old 08-03-2010 , 21:03   Re: Handles not closing!!!
Reply With Quote #2

single time timers are close automatically

you dont have to use &Handle:, just Handle:

are you creating many timers? use sm_dump_handles handles.txt to dump all handles in a file so you can see which type of handles they are
DarkEnergy is offline
retsam
Veteran Member
Join Date: Aug 2008
Location: so-cal
Old 08-03-2010 , 21:14   Re: Handles not closing!!!
Reply With Quote #3

Most likely youre not handling your timer handles properly. Would kinda have to see how youre doing stuff to get a better idea...
__________________
retsam is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 08-04-2010 , 05:29   Re: Handles not closing!!!
Reply With Quote #4

If you have repeated timers you should save the handles, like in an array if you use a timer per player.

Quote:
Originally Posted by DarkEnergy View Post
you dont have to use &Handle:, just Handle:
ToClose must be passed as a reference, so the variable itself can be reset too.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
DarkEnergy
SourceMod Donor
Join Date: Apr 2008
Location: Georgia Tech, MSECE
Old 08-04-2010 , 10:01   Re: Handles not closing!!!
Reply With Quote #5

Handle: automatically passes it by reference

ie
public Action:timercall(Handle:timer,any:data)
DarkEnergy is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 08-04-2010 , 10:19   Re: Handles not closing!!!
Reply With Quote #6

Maybe I missed something, but as far as I know a handle variable is a regular cell variable tagged as Handle. It's not automatically passed by reference in function calls.

Quote:
Originally Posted by almcaeobtac View Post
(...) how do you close timer handles once they are finished?
If the timer is finished you only need to reset the handle variable. Reset your handle variable within the timer callback when you know the timer is stopping, like right before you return Plugin_Stop for repeatable timers, or at the end of the callback for regular timers.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)

Last edited by rhelgeby; 08-04-2010 at 10:27.
rhelgeby is offline
Send a message via MSN to rhelgeby
DarkEnergy
SourceMod Donor
Join Date: Apr 2008
Location: Georgia Tech, MSECE
Old 08-04-2010 , 12:12   Re: Handles not closing!!!
Reply With Quote #7

i am pretty sure handles are automatically passed by reference, just like arrays
DarkEnergy is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 08-04-2010 , 13:02   Re: Handles not closing!!!
Reply With Quote #8

Quote:
Originally Posted by DarkEnergy View Post
i am pretty sure handles are automatically passed by reference, just like arrays
Nope.
__________________
plop
p3tsin is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 08-04-2010 , 18:34   Re: Handles not closing!!!
Reply With Quote #9

I think you're mixing the handle reference itself with a variable reference.

In most programming languages primitives are passed by value, objects by reference (not always the case though, like in Java which is always pass by value).

The handle (just a number) is passed as value, but is used to refer to an object. An array is considered an object because it's not a single value and therefore passed by reference.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)

Last edited by rhelgeby; 08-04-2010 at 18:39.
rhelgeby is offline
Send a message via MSN to rhelgeby
Monkeys
Veteran Member
Join Date: Jan 2010
Old 08-04-2010 , 19:24   Re: Handles not closing!!!
Reply With Quote #10

Distilled from ^.
You can close a handle that's been passed, since you'll be "closing" the object it references with its value.
You can't set the value of a handle that's been passed, only of the buffer that it stored the passed handle in.

PHP Code:
public Starter()
{
new 
Handle:HandleOrig PointToSomeObjectThroughSomeFunction();
Function(
HandleOrig);//the passed Handle
}
public Function(
Handle:HandleBuffer//the Handle buffer
{
CloseHandle(HandleBuffer); //This will also close the HandleOrig, as it points to the same object
HandleBuffer INVALID_HANDLE//This will only set HandleBuffer, not HandleOrig, as it's not a reference.


TL;DR: the & has to stay.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys 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 18:51.


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