You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The backtrace says it is crashing in [window close] in FigureManager_dealloc. In FigureManager_new, the self->window is allocated, and in FigureManager_init it is initialized using initWithContentRect. If we raise from __init__ immediately, then the super-init is not called and the window is not initialized. Presumably an uninitialized window cannot be closed, but I'm not sure how to check if it has been.
It seems like the real issue is a misuse/disuse of tp_alloc, tp_init, tp_finalize, and tp_dealloc.
The window ought to be allocated in a custom tp_alloc. Currently, this is done in tp_init.
The tp_init should call some init method on the window.
The window should be closed in tp_finalize. This should be decoupled from releasing it. I think that can be done by setting isReleasedWhenClosed to false during tp_init.
@joelfrederico I milestoned this as 3.6 as you did not label this as a regression, but if there is an easy fix to reduce segfaults, we can definitely backport it.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Presumably an uninitialized window cannot be closed, but I'm not sure how to check if it has been.
I don't yet possess deep knowledge regarding the proper use of tp_alloc/tp_new/tp_init in the Python world.
In the Objective-C world, an -init… method should always be called immediately after +alloc. Calling any other instance method on an object you just allocated before calling -init… is undefined behavior.123
I believe that each tp_new callback should only call tp_alloc and not instantiate an uninitialized Objective-C object. Each tp_init callback should then create a fully initialized Objective-C object via an +alloc/-init… pair.
Activity
QuLogic commentedon Dec 18, 2021
The backtrace says it is crashing in
[window close]inFigureManager_dealloc. InFigureManager_new, theself->windowis allocated, and inFigureManager_initit is initialized usinginitWithContentRect. If we raise from__init__immediately, then the super-init is not called and the window is not initialized. Presumably an uninitialized window cannot be closed, but I'm not sure how to check if it has been.joelfrederico commentedon Dec 18, 2021
It seems like the real issue is a misuse/disuse of tp_alloc, tp_init, tp_finalize, and tp_dealloc.
The window ought to be allocated in a custom tp_alloc. Currently, this is done in tp_init.
The tp_init should call some init method on the window.
The window should be closed in tp_finalize. This should be decoupled from releasing it. I think that can be done by setting isReleasedWhenClosed to false during tp_init.
The window should be released in tp_dealloc.
Is that all correct?
tacaswell commentedon Dec 18, 2021
@joelfrederico I milestoned this as 3.6 as you did not label this as a regression, but if there is an easy fix to reduce segfaults, we can definitely backport it.
tacaswell commentedon Feb 9, 2023
Checking, the state is current the same, however if I am reading this correctly we only have the issue if we raise in the
__init__?github-actions commentedon Apr 13, 2026
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
tacaswell commentedon Apr 13, 2026
Suspect that this is still an issue.
iccir commentedon May 30, 2026
I don't yet possess deep knowledge regarding the proper use of
tp_alloc/tp_new/tp_initin the Python world.In the Objective-C world, an
-init…method should always be called immediately after+alloc. Calling any other instance method on an object you just allocated before calling-init…is undefined behavior.123I believe that each
tp_newcallback should only calltp_allocand not instantiate an uninitialized Objective-C object. Eachtp_initcallback should then create a fully initialized Objective-C object via an+alloc/-init…pair.Footnotes
"But the resulting object is not yet usable." from Object Allocation ↩
"You must use an init... method to complete the initialization process." from +alloc ↩
"immediately" and "An init message is coupled with an alloc … message in the same line of code" from -init ↩