google / google/or-tools

Uncleaned cyclic reference in python Routing lib

Open
#4,753 0 comments 0 reactions 1 assignee Claimed by @Mizux View on GitHub
Bug Lang: Python Solver: Routing
Dominant language
C++
Stars
14.1k
Forks
2.5k
Avg merge
8h 39m
Merged PRs (30d)
72

Description

**What version of OR-Tools and what language are you using?**
Version: 9.14.6206
Language: Python

**Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)**
Routing Solver

**What operating system (Linux, Windows, ...) and version?**
Linux

**What did you do?**
I use callback for each solution with link on RoutingModel to track the progress of the solution:
```py
callback = SolutionCallback(routing)
routing.AddAtSolutionCallback(callback)
```
Where callback:
```py
class SolutionCallback:
def __del__(self):
print("DELETE SolutionCallback")
def __init__(self, routing: pywrapcp.RoutingModel):
print("CREATE SolutionCallback")
self.model = routing
def __call__(self):
pass
```

And in log console I see only "CREATE SolutionCallback".

Memory usage for example from official cite (https://developers.google.com/optimization/routing/vrp) with solution callback (I run it in loop 10_000 times):

Image

I can remove this cyclic reference by:
```
callback.model = None
```
After that callback remove.

I didn't find that I need to nullified it in the documentation. I think it is unexpected behavior because by default python can remove cyclic reference.

**What did you expect to see**
Automatically remove circular references or make a new mention in the documentation that the dependency needs to be nullified

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.