Possible to clear PathPool?

Hi,

Just wondering, is it possible to clear the Path Pool? Having some leaks and I feel Path Pool may be involved somewhere, so if I could clear the pool it’d help verify if that is the issue (Path Pool still seems to be used even if I disable pool).

Thanks!

Hi

If you disable the pooling using the compiler directive the path pool will just return new instances every time and it will ignore any requests to pool objects.

Hi,

Yeah I was trying that but it didn’t seem to apply. I hadn’t noticed the errors though when I clicked “Apply” button in Optimization settings. So I had to make a few changes to the code so it’d work.

In OptimizationHandler.cs, I had to add the following after line 37 due to errors (seems Unity has made changes to build targets):

if (buildTypes[i] == (int)BuildTargetGroup.PS3 || buildTypes[i] == (int)BuildTargetGroup.XBOX360 ||
buildTypes[i] == (int)BuildTargetGroup.WP8 || buildTypes[i] == (int)BuildTargetGroup.BlackBerry)
{
continue;
}

Also, in ListPool.cs, at line 146 I had to change:

if !ASTAR_OPTIMIZE_POOLING

to

if !ASTAR_NO_POOLING && !ASTAR_OPTIMIZE_POOLING

as there is a compilation error when Pooling was disabled.

Maybe these issues are just present for me. I’m using Unity 5.5.0p3 (Mac) and have version 3.8.7 Pro of A* Pathfinding project.

Thanks.

Hi

Thanks for the heads up. My automated testing script didn’t catch that one (fixed that now, it never tested with ASTAR_NO_POOLING without ASTAR_OPTIMIZE_POOLING).

I’m not sure why you have to add those lines to the OptimizationHandler however. What errors does Unity output?

I’m not sure why you have to add those lines to the OptimizationHandler however. What errors does Unity output?

It gives the following errors (each error appears about 16 times):

PlayerSettings Validation: Requested build target group (5) doesn't exist; #define symbols for scripting won't be added.
UnityEditor.PlayerSettings:SetScriptingDefineSymbolsForGroup(BuildTargetGroup, String)
Pathfinding.OptimizationHandler:SetDefineSymbols(Dictionary`2) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:58)
Pathfinding.OptimizationHandler:DisableDefine(String) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:77)
Pathfinding.OptimizationHandler:ApplyDefines(List`1) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:126)
AstarPathEditor:DrawOptimizationSettings() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:605)
AstarPathEditor:DrawMainArea() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:550)
AstarPathEditor:OnInspectorGUI() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:303)
UnityEditor.DockArea:OnGUI()

PlayerSettings Validation: Requested build target group (6) doesn't exist; #define symbols for scripting won't be added.
UnityEditor.PlayerSettings:SetScriptingDefineSymbolsForGroup(BuildTargetGroup, String)
Pathfinding.OptimizationHandler:SetDefineSymbols(Dictionary`2) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:58)
Pathfinding.OptimizationHandler:DisableDefine(String) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:77)
Pathfinding.OptimizationHandler:ApplyDefines(List`1) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:126)
AstarPathEditor:DrawOptimizationSettings() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:605)
AstarPathEditor:DrawMainArea() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:550)
AstarPathEditor:OnInspectorGUI() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:303)
UnityEditor.DockArea:OnGUI()

PlayerSettings Validation: Requested build target group (15) doesn't exist; #define symbols for scripting won't be added.
UnityEditor.PlayerSettings:SetScriptingDefineSymbolsForGroup(BuildTargetGroup, String)
Pathfinding.OptimizationHandler:SetDefineSymbols(Dictionary`2) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:58)
Pathfinding.OptimizationHandler:DisableDefine(String) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:77)
Pathfinding.OptimizationHandler:ApplyDefines(List`1) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:126)
AstarPathEditor:DrawOptimizationSettings() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:605)
AstarPathEditor:DrawMainArea() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:550)
AstarPathEditor:OnInspectorGUI() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:303)
UnityEditor.DockArea:OnGUI()

PlayerSettings Validation: Requested build target group (16) doesn't exist; #define symbols for scripting won't be added.
UnityEditor.PlayerSettings:SetScriptingDefineSymbolsForGroup(BuildTargetGroup, String)
Pathfinding.OptimizationHandler:SetDefineSymbols(Dictionary`2) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:58)
Pathfinding.OptimizationHandler:DisableDefine(String) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:77)
Pathfinding.OptimizationHandler:ApplyDefines(List`1) (at Assets/AstarPathfindingProject/Editor/OptimizationHandler.cs:126)
AstarPathEditor:DrawOptimizationSettings() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:605)
AstarPathEditor:DrawMainArea() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:550)
AstarPathEditor:OnInspectorGUI() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:303)
UnityEditor.DockArea:OnGUI()

And the settings are not applied. Also, In the Inspector, a number of optimisation toggles have the warning:

This define is not consistent for all build targets, some have it enabled, some have it disabled. Press Apply to change to the same value.

My patch does not get rid for the inspector warning.

Ah. Yeah it’s annoying that there is no way to detect which build targets are deprecated using a script.

I have just uploaded 3.8.8.1 which prevents the script from trying to set those build targets after the version of Unity when they were deprecated. It got rid of that warning for me at least, not sure why it wasn’t removed for you.

My understanding is that the warnings are there because previously they were set for the now deprecated build targets, and now that I’ve changed the value it’s not updating it for the deprecated build targets as it can’t.

Anyway, glad you were able to sort it out quickly, thanks!

I don’t think so. It should only check the non-deprecated build targets.

Just back to the original issue, setting the system not to pool paths solved the memory leaks I was having. The problem is that some of our agent objects are remaining in memory after a scene change because they are been referenced by a path in the pool.

Maybe I’m barking up the wrong tree, but the memory profiler shows that the PathPool is keeping the reference alive.

OnPathDelegate has a reference to the Seeker.

In the agent’s onDestroy function, I try to ensure the seeker is cleared but it doesn’t appear to be working.
_seeker.ReleaseClaimedPath();
_seeker.pathCallback = null;
_seeker = null;

This is how I request a path:

RandomPath randomPath = RandomPath.Construct(startPosition, 10000, null);
_agent.AgentSeeker.StartPath(randomPath, OnPathSearchComplete);

protected virtual void OnPathSearchComplete(Path path)
{
    // Claim the path
    path.Claim(this);

    //Do stuff....

    // Release the path
    path.Release(this);
}

The memory leak isn’t happening for all agents, so I’m guessing that it only happens if an agent was in the process of requesting a path when the scene changed. Can you see anything that I am doing incorrectly?

Thanks.

Hm. I think this can be a similar issue as another user reported a while ago.

Try to add

callback = null

as the last line in the Path.OnEnterPool method (also do the same thing for MultiTargetPath if you are using that).

I have fixed this in my dev version, but it has not been released yet.

1 Like

Btw, that looks like a pretty nifty memory profiler.

Cool, I’ll check that out and report back, thanks!

It’s the memory profiler one of the Unity devs started working on with the aim to add it to Unity itself. Unfortunately nothing has come of it, but you can still grab it here. I think you have to make a few changes to get it working with the latest unity.

It’s very work-in-progress with a lot of rough edges, but I find it very useful (wouldn’t have noticed this issue among others without it).

Yeah, that seems to have fixed the issue. Thanks!

1 Like