Opened 2 months ago

Closed 7 weeks ago

#28498 closed defect (fixed)

Memory leak in BasisExchangeMatroid.components

Reported by: tmonteil Owned by:
Priority: major Milestone: sage-9.0
Component: memleak Keywords: memleak
Cc: Rudi, jdemeyer Merged in:
Authors: Thierry Monteil Reviewers: Vincent Delecroix
Report Upstream: N/A Work issues:
Branch: e9ed458 (Commits) Commit: e9ed458aa343140e07f03dbd760d61e5bfe73b28
Dependencies: Stopgaps:

Description (last modified by slelievre)

As reported in this ask question, there is a memory leak in BasisExchangeMatroid.components, see:

sage: G = [g for g in graphs.nauty_geng("12 16:16 -Ct")]
sage: for _ in range(20):
....:     for g in G:
....:         A = g.incidence_matrix()
....:         M = Matroid(A, ring = GF(2))
....:         if M.is_connected():
....:             pass
....:     print(get_memory_usage())
....:     
8539.23046875
8543.7421875
8547.73828125
8551.734375
8555.73046875
8559.59765625
8563.59375
8566.9453125
8570.94140625
8574.9375
8578.2890625
8582.28515625
8586.15234375
8589.6328125
8593.62890625
8597.49609375
8600.9765625
8604.84375
8608.83984375
8612.3203125

The memory leak is because sig_free is missing.

Change History (9)

comment:1 Changed 2 months ago by tmonteil

  • Branch set to u/tmonteil/memory_leak_in_basisexchangematroid_components

comment:2 Changed 2 months ago by tmonteil

  • Commit set to e9ed458aa343140e07f03dbd760d61e5bfe73b28

After the fix:

sage: G = [g for g in graphs.nauty_geng("12 16:16 -Ct")]
sage: for _ in range(20):
....:     for g in G:
....:         A = g.incidence_matrix()
....:         M = Matroid(A, ring = GF(2))
....:         if M.is_connected():
....:             pass
....:     print(get_memory_usage())
....:     
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375
8462.484375

I am not sure whether this should be doctested.


New commits:

db6182b#28498 : remove trailing spaces
e9ed458#28498 : fix memleak

comment:3 Changed 2 months ago by tmonteil

  • Cc Rudi jdemeyer added
  • Status changed from new to needs_review

comment:4 Changed 2 months ago by vdelecroix

  • Reviewers set to Vincent Delecroix

Nice catch! Such memory leaks should be doctested for each code snippet (ie running the same code 100 times should not increase memory usage). I am not sure it makes sense at the level of this single function.

comment:5 Changed 2 months ago by vdelecroix

  • Status changed from needs_review to positive_review

comment:6 Changed 2 months ago by Rudi

Sorry for making this mistake in the first place, and thanks for fixing!

comment:7 Changed 2 months ago by slelievre

  • Description modified (diff)
  • Keywords memleak added

comment:8 Changed 7 weeks ago by chapoton

  • Milestone changed from sage-8.9 to sage-9.0

moving milestone to 9.0 (after release of 8.9)

comment:9 Changed 7 weeks ago by vbraun

  • Branch changed from u/tmonteil/memory_leak_in_basisexchangematroid_components to e9ed458aa343140e07f03dbd760d61e5bfe73b28
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.