Hi Guys, Thanks for the replies. I think this is enough info to know that it happens on multiple systems and that it's not just the cocalc enhanced version of sage. I have created: https://trac.sagemath.org/ticket/31511#ticket for this.
In the meantime I found the problem is already with the srange command. So the integer multiplication seems to be a red herring. ~$ sage ┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 9.2, Release Date: 2020-10-24 │ │ Create a "Sage Worksheet" file for the notebook interface. │ │ Enhanced for CoCalc. │ │ Using Python 3.8.5. Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘ sage: M = 3000 ....: import gc ....: gc.collect() ....: mem = get_memory_usage() ....: for i in range(10000): ....: R = srange(M) ....: gc.collect() ....: print("memory usage 10k:", get_memory_usage(mem)) ....: mem = get_memory_usage() ....: for i in range(20000): ....: R = srange(M) ....: gc.collect() ....: print("memory usage 20k:", get_memory_usage(mem)) 434 0 memory usage 10k: 884.4296875 0 memory usage 20k: 1770.71875 On Thursday, 18 March 2021 at 16:01:56 UTC+1 David Joyner wrote: > On Thu, Mar 18, 2021 at 6:56 AM Maarten Derickx <m.derick...@gmail.com> > wrote: > >> Hi All, >> >> tldr: the bottom of this post contains example code of which I would like >> the results on some other systems. >> >> I recently encountered a memory leak in the relatively innocently looking >> code: >> >> d = 27 >> M = 109 >> for i in range(10000): >> for a in srange(M): >> for r in srange(d): >> tmp = r*a >> >> However it doesn't seem to be on all platforms that sage supports. For >> example on cocalc (ubuntu 20.04) one gets: >> >> ~$ sage >> ┌────────────────────────────────────────────────────────────────────┐ >> │ SageMath version 9.2, Release Date: 2020-10-24 │ >> │ Create a "Sage Worksheet" file for the notebook interface. │ >> │ Enhanced for CoCalc. │ >> │ Using Python 3.8.5. Type "help()" for help. │ >> └────────────────────────────────────────────────────────────────────┘ >> sage: import gc >> ....: gc.collect() >> ....: mem = get_memory_usage() >> ....: d = 27 >> ....: M = 109 >> ....: for i in range(10000): >> ....: for a in srange(M): >> ....: for r in srange(1,d): >> ....: tmp = r*a >> ....: gc.collect() >> ....: print("memory usage 10k:", get_memory_usage(mem)) >> ....: mem = get_memory_usage() >> ....: for i in range(20000): >> ....: for a in srange(M): >> ....: for r in srange(1,d): >> ....: tmp = r*a >> ....: gc.collect() >> ....: print("memory usage 20k:", get_memory_usage(mem)) >> ....: >> >> 434 >> 0 >> memory usage 10k: 9.15234375 >> 0 >> memory usage 20k: 21.3984375 >> >> >> showing clear indication of a memory leak. While on my own laptop (OS X >> 10.13.6) I get: >> >> >> >> ~ mderickx$ sage >> ┌────────────────────────────────────────────────────────────────────┐ >> │ SageMath version 9.2, Release Date: 2020-10-24 │ >> │ Using Python 3.8.5. Type "help()" for help. │ >> └────────────────────────────────────────────────────────────────────┘ >> sage: import gc >> ....: gc.collect() >> ....: mem = get_memory_usage() >> ....: d = 27 >> ....: M = 109 >> ....: for i in range(10000): >> ....: for a in srange(M): >> ....: for r in srange(1,d): >> ....: tmp = r*a >> ....: gc.collect() >> ....: print("memory usage 10k:", get_memory_usage(mem)) >> ....: mem = get_memory_usage() >> ....: for i in range(20000): >> ....: for a in srange(M): >> ....: for r in srange(1,d): >> ....: tmp = r*a >> ....: gc.collect() >> ....: print("memory usage 20k:", get_memory_usage(mem)) >> ....: >> 278 >> 0 >> memory usage 10k: 0.0 >> 0 >> memory usage 20k: 0.0 >> >> >> so here the memory leak does not occur. However I don't have any other >> systems to which I have access to. So I was wondering if people could >> execute the code below on some other systems and report back here to see >> where the leaking is actually occurring. Since I do not have access to a >> plain vanilla sage install on ubuntu, *I am especially interested if on >> ubuntu the non cocalc enhanced version of sage also produces a memory leak >> for the following code:* >> >> import gc >> gc.collect() >> mem = get_memory_usage() >> d = 27 >> M = 109 >> for i in range(10000): >> for a in srange(M): >> for r in srange(1,d): >> tmp = r*a >> gc.collect() >> print("memory usage 10k:", get_memory_usage(mem)) >> mem = get_memory_usage() >> for i in range(20000): >> for a in srange(M): >> for r in srange(1,d): >> tmp = r*a >> gc.collect() >> print("memory usage 20k:", get_memory_usage(mem)) >> >> > This is in sage 9.1.rc5 running on ubuntu 20.4 on a dell inspiron laptop. > It's an old version of sage but I hope it helps: > > > sage: gc.collect() > ....: mem = get_memory_usage() > ....: d = 27 > ....: M = 109 > ....: for i in range(10000): > ....: for a in srange(M): > ....: for r in srange(1,d): > ....: tmp = r*a > ....: gc.collect() > ....: print("memory usage 10k:", get_memory_usage(mem)) > ....: mem = get_memory_usage() > ....: for i in range(20000): > ....: for a in srange(M): > ....: for r in srange(1,d): > ....: tmp = r*a > ....: gc.collect() > ....: print("memory usage 20k:", get_memory_usage(mem)) > ....: > 176 > 0 > memory usage 10k: 10.0546875 > 0 > memory usage 20k: 21.3984375 > > > >> -- >> You received this message because you are subscribed to the Google Groups >> "sage-devel" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sage-devel+...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/sage-devel/5882460b-842c-49c4-b33b-fae1c7986db9n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/sage-devel/5882460b-842c-49c4-b33b-fae1c7986db9n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/48cf8a2f-e9a0-4aa2-86bd-bb5156b62065n%40googlegroups.com.