Is there a way to find out where a Python object was instantiated the first time? Like the line number or even the full traceback at the creation?
For memory profiling I’d like to examine all objects after the run. (I’m aware of memory profiling tools, but they are hard to install or don’t do this task).
It’s not possible in native Python to obtain this information from an object after it’s been created, but you can override the
__new__()method on a base class to record it somewhere on the object (getting it from theinspectmodule).