[issue46717] Raising exception multiple times leaks memory

2022-02-22 Thread Irit Katriel


Change by Irit Katriel :


--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46717] Raising exception multiple times leaks memory

2022-02-11 Thread Irit Katriel


Irit Katriel  added the comment:

"raise exc" adds the current frame to the traceback of exc. If you want to 
clear the previous traceback before raising you can do that with

raise exc.with_traceback(None)

--
resolution:  -> not a bug

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46717] Raising exception multiple times leaks memory

2022-02-10 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Did you try to print a traceback of the exception?

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46717] Raising exception multiple times leaks memory

2022-02-10 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

I reproduced as far back as Python 3.6 with this:

---
import gc

exc = Exception()
deltas = []

for i in range(2, 15):
ref1 = len(gc.get_objects())
for j in range(2**i):
try:
raise exc
except Exception:
pass
ref2 = len(gc.get_objects())
deltas.append(ref2 - ref1)

print(deltas)
# [4, 8, 16, 9, 64, 128, 256, 512, 1024, 2048, 4072, 8192, 16384]
---


Note that the memory does get freed up once the exception is deleted:

---
import gc

deltas = []

for i in range(2, 15):
ref1 = len(gc.get_objects())

exc = Exception()
for j in range(2**i):
try:
raise exc
except Exception:
pass
del exc  # <<<

ref2 = len(gc.get_objects())
deltas.append(ref2 - ref1)

print(deltas)
# [0, 0, 0, 0, 0, -14, 0, 0, 0, 0, -14, 0, 0]
---

--
nosy: +Dennis Sweeney, iritkatriel

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46717] Raising exception multiple times leaks memory

2022-02-10 Thread Ethan Furman


Change by Ethan Furman :


--
nosy: +ethan.furman

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46717] Raising exception multiple times leaks memory

2022-02-10 Thread George Gensure


New submission from George Gensure :

Instantiating an exception and raising it multiple times causes 1 frame and 2 
traceback objects to remain allocated for each raise. The attached example 
causes python to consume 8GB of ram after a few seconds of execution on 
Windows/Linux.

--
components: Interpreter Core
files: exc.py
messages: 413035
nosy: ggensure
priority: normal
severity: normal
status: open
title: Raising exception multiple times leaks memory
type: resource usage
versions: Python 3.11
Added file: https://bugs.python.org/file50619/exc.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com