coin-or / CyLP

A Python interface to CLP, CBC, and CGL to solve LPs and MIPs.
Other
182 stars 68 forks source link

Fix leak of CyCoinModel CppSelf #197

Open bkurtz opened 5 months ago

bkurtz commented 5 months ago

CyCoinModel allocates a C++ object CppSelf and fails to deallocate it.

A simple test script allocating CyCoinModel objects in a loop and deleting them shows significant memory leaked prior to this patch, and negligible memory leaked after (run in a python3.9 docker image):

import gc
import resource
import cylp.cy

def maxrss() -> int:
    return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss

print("runs\tmaxrss")
for i in range(10000):
    model = cylp.cy.CyCoinModel()
    del model
    gc.collect()
    if i % 100 == 0:
        print(f"{i}\t{maxrss()}")

mem_usage

CLAassistant commented 5 months ago

CLA assistant check
All committers have signed the CLA.