AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Memory leak on ADT Arrays (https://forums.alliedmods.net/showthread.php?t=312514)

alerad 12-06-2018 21:18

Memory leak on ADT Arrays
 
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.

Starbish 12-06-2018 21:36

Re: Memory leak on ADT Arrays
 
You should delete all handles manually in your g_bulkNotLoadedClientsArray array.

I mean, delete tempArray which you pushed on setClientsArray().

SZOKOZ 12-07-2018 06:01

Re: Memory leak on ADT Arrays
 
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);
}


alerad 12-08-2018 09:26

Re: Memory leak on ADT Arrays
 
Quote:

Originally Posted by SZOKOZ (Post 2627185)
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.

Fyren 12-08-2018 12:10

Re: Memory leak on ADT Arrays
 
You probably need to post your code.

SZOKOZ 12-08-2018 12:49

Re: Memory leak on ADT Arrays
 
And dem logs showing you the array leaks.

alerad 12-09-2018 14:54

Re: Memory leak on ADT Arrays
 
Quote:

Originally Posted by Fyren (Post 2627637)
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);
}


Fyren 12-10-2018 21:27

Re: Memory leak on ADT Arrays
 
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.

Mitchell 12-11-2018 00:32

Re: Memory leak on ADT Arrays
 
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)

ofir753 12-11-2018 02:00

Re: Memory leak on ADT Arrays
 
Sometimes its easier to work with pre-allocated array.


All times are GMT -4. The time now is 13:00.

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