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

Memory leak on ADT Arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alerad
Junior Member
Join Date: Mar 2016
Old 12-06-2018 , 21:18   Memory leak on ADT Arrays
Reply With Quote #1

Hey, i'm having an issue with an ADT Array, which stores another ADT array.

The following piece of code is giving me memleaks and i'm not sure what else to try.

Code:
public void setClientsArray() {
	Handle tempArray = new ArrayList();
        PushArrayCell(tempArray, i);
	PushArrayCell(g_bulkNotLoadedClientsArray, tempArray);
}
I've tried doing

Code:
OnMapEnd {
      CloseHandle(g_bulkNotLoadedClientsArray);
}
Also tried iterating over the bulk array and trying to close each handle individually, still leaking.

Anyone got any idea on how to do this? It's driving me nuts and i'd have to refactor a fair amount of code to approach it on another way. Thanks in advance.
alerad is offline
Starbish
AlliedModders Donor
Join Date: Oct 2011
Location: South Korea
Old 12-06-2018 , 21:36   Re: Memory leak on ADT Arrays
Reply With Quote #2

You should delete all handles manually in your g_bulkNotLoadedClientsArray array.

I mean, delete tempArray which you pushed on setClientsArray().
__________________
Starbish is offline
SZOKOZ
Member
Join Date: Jan 2014
Old 12-07-2018 , 06:01   Re: Memory leak on ADT Arrays
Reply With Quote #3

If the variable "i" is another handle, you need to manually close that too. Then close each arraylist manually.

E.g.
Code:
for (int i = 0; i < g_bulkNotLoadedClientsArray.Length; i++)
{
    ArrayList tempArray = view_as<ArrayList>(g_bulkNotLoadedClientsArray.Get(i));
    for (int j = 0; j < tempArray.Length; j++)
    {
        CloseHandle(tempArray.Get(j));
    }
    CloseHandle(tempArray);
}
__________________
May still be available for SM scripting. Just look at my Steam profile regarding my availability.
My Steam

Last edited by SZOKOZ; 12-07-2018 at 06:09. Reason: Added example
SZOKOZ is offline
alerad
Junior Member
Join Date: Mar 2016
Old 12-08-2018 , 09:26   Re: Memory leak on ADT Arrays
Reply With Quote #4

Quote:
Originally Posted by SZOKOZ View Post
If the variable "i" is another handle, you need to manually close that too. Then close each arraylist manually.

E.g.
Code:
for (int i = 0; i < g_bulkNotLoadedClientsArray.Length; i++)
{
    ArrayList tempArray = view_as<ArrayList>(g_bulkNotLoadedClientsArray.Get(i));
    for (int j = 0; j < tempArray.Length; j++)
    {
        CloseHandle(tempArray.Get(j));
    }
    CloseHandle(tempArray);
}

Hey, yeah, that's what i've tried to do when I said I tried iterating over the bulk array, however, doing this for some reason generates even more ArrayCell leaks.
alerad is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 12-08-2018 , 12:10   Re: Memory leak on ADT Arrays
Reply With Quote #5

You probably need to post your code.
Fyren is offline
SZOKOZ
Member
Join Date: Jan 2014
Old 12-08-2018 , 12:49   Re: Memory leak on ADT Arrays
Reply With Quote #6

And dem logs showing you the array leaks.
__________________
May still be available for SM scripting. Just look at my Steam profile regarding my availability.
My Steam
SZOKOZ is offline
alerad
Junior Member
Join Date: Mar 2016
Old 12-09-2018 , 14:54   Re: Memory leak on ADT Arrays
Reply With Quote #7

Quote:
Originally Posted by Fyren View Post
You probably need to post your code.
Oh right lol, really burnt out.

Code:
	
OnMapEnd() {
        for (int i = 0; i < GetArraySize(g_bulkNotLoadedClientsArray); i++)
	{
	    ArrayList tempArray = view_as<ArrayList>(GetArrayCell(g_bulkNotLoadedClientsArray, i));
	    for (int j = 0; j < tempArray.Length; j++)
	    {
	        CloseHandle(GetArrayCell(tempArray, j));
	    }
	    CloseHandle(tempArray);
	}
        CloseHandle(g_bulkNotLoadedClientsArray);
}
alerad is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 12-10-2018 , 21:27   Re: Memory leak on ADT Arrays
Reply With Quote #8

I meant all of it, at least concerning the handles. That'd include handle creation, closing, and also anywhere you put things into your array.
Fyren is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 12-11-2018 , 00:32   Re: Memory leak on ADT Arrays
Reply With Quote #9

Honestly you should just avoid putting an ArrayList within another ArrayList, sounds like a headache to deal with (something you've already started to have)
Mitchell is offline
ofir753
Senior Member
Join Date: Aug 2012
Old 12-11-2018 , 02:00   Re: Memory leak on ADT Arrays
Reply With Quote #10

Sometimes its easier to work with pre-allocated array.
ofir753 is offline
Reply


Thread Tools
Display Modes

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 15:31.


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