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

Memory leaks


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
maciasbarlinek
Senior Member
Join Date: May 2015
Old 02-11-2017 , 18:34   Memory leaks
Reply With Quote #1

Hello,

I made my plugin which has about 33 000 lines
When my server has a lot of players my plugin is unloading automatically by sourcemod with reason

Code:
L 02/12/2017 - 00:09:43: [SM] MEMORY LEAK DETECTED IN PLUGIN (file "JBOfficial.smx")
L 02/12/2017 - 00:09:43: [SM] Unloading plugin to free 32658 handles.
L 02/12/2017 - 00:09:43: [SM] Contact the author(s) of this plugin to correct this error.
L 02/12/2017 - 00:09:43: -------------------------------------------------------------------------
L 02/12/2017 - 00:09:43: Type   IBaseMenu           |   Count   1
L 02/12/2017 - 00:09:43: Type   IDatabase           |   Count   32557
L 02/12/2017 - 00:09:43: Type   Timer               |   Count   3
L 02/12/2017 - 00:09:43: Type   Regex               |   Count   97
L 02/12/2017 - 00:09:43: -- Approximately 299 bytes of memory are in use by (32658) Handles.
I made debug by command sm_dump_handles:
Spoiler


What I should do? I read another topics but still i don't have solution..
Thanks a lot
__________________
cam0 & lingzhidiyu - The best users

Last edited by maciasbarlinek; 02-11-2017 at 18:39.
maciasbarlinek is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 02-11-2017 , 18:43   Re: Memory leaks
Reply With Quote #2

looks like you're calling SQL_Connect (or similar) a lot and never closing the handles, you should close them O-O
Miu is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 02-11-2017 , 18:47   Re: Memory leaks
Reply With Quote #3

Looks like you are either creating loads of database handles, or you aren't closing them and they are building up over time.

Edit: Well now I feel silly

Last edited by Kolapsicle; 02-11-2017 at 18:48.
Kolapsicle is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 02-11-2017 , 19:59   Re: Memory leaks
Reply With Quote #4

Any reason you don't use threaded queries?
Addicted. is offline
maciasbarlinek
Senior Member
Join Date: May 2015
Old 02-11-2017 , 20:03   Re: Memory leaks
Reply With Quote #5

I use..

Example:
Code:
                        Format(g_sqlBuffer_Members, sizeof(g_sqlBuffer_Members), "UPDATE %s set Portfel = %d WHERE ID = %d", MySQL_TABLE_NAME_MEMBERs, portfel, ID);
                        SQL_TQuery(DB_MySQL, SQLErrorCheckCallback, g_sqlBuffer_Members);
Code:
public void SQLErrorCheckCallback(Handle owner, Handle hndl, const char[] error, any data)
{
    if(hndl == INVALID_HANDLE)
    {
        DB_MySQL = INVALID_HANDLE;
        DB_Connect();
        LogError("[ MySQL ] Zapytanie do bazy danych nie powiodlo sie. Blad: %s", error);
    }
}
__________________
cam0 & lingzhidiyu - The best users
maciasbarlinek is offline
maciasbarlinek
Senior Member
Join Date: May 2015
Old 02-11-2017 , 20:22   Re: Memory leaks
Reply With Quote #6

Aaa man i understand you..
I should replace SQL_Query to SQL_TQUERY?
__________________
cam0 & lingzhidiyu - The best users

Last edited by maciasbarlinek; 02-11-2017 at 20:22.
maciasbarlinek is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-11-2017 , 20:28   Re: Memory leaks
Reply With Quote #7

Yes.
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS
OSWO is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 02-12-2017 , 08:23   Re: Memory leaks
Reply With Quote #8

Also, don't reconnect to the database each time a query error occurs.. may have been triggered by something else, not necessarely connection problems.
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 02-12-2017 , 08:39   Re: Memory leaks
Reply With Quote #9

also note, just setting a handle variable to INVALID_HANDLE will not close the previous handle stored, use delete instead (it does both close the handle and set the variable to INVALID_HANDLE)
__________________

Last edited by WildCard65; 02-12-2017 at 08:40.
WildCard65 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:41.


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