Example to reproduce the bug (using Python trunk): --- from gc import collect import _lsprof def callMethod(obj): obj.clear() collect() obj = _lsprof.Profiler() obj.enable() callMethod(obj) obj.enable() del obj collect() --- The problem is that the profiler is still running when exiting callMethod() and so it tries to use callMethod context which was free'd just before by profiler_clear().