Title: [MNT]: macOS backend should always pair `+alloc`/`-init` calls · Issue #31798 · matplotlib/matplotlib · GitHub
Open Graph Title: [MNT]: macOS backend should always pair `+alloc`/`-init` calls · Issue #31798 · matplotlib/matplotlib
X Title: [MNT]: macOS backend should always pair `+alloc`/`-init` calls · Issue #31798 · matplotlib/matplotlib
Description: Summary I mentioned the following in #21788: In Objective-C, 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...
Open Graph Description: Summary I mentioned the following in #21788: In Objective-C, an -init… method should always be called immediately after +alloc. Calling any other instance method on an object you just allocated bef...
X Description: Summary I mentioned the following in #21788: In Objective-C, an -init… method should always be called immediately after +alloc. Calling any other instance method on an object you just allocated bef...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31798
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[MNT]: macOS backend should always pair `+alloc`/`-init` calls","articleBody":"### Summary\n\nI mentioned the following in #21788:\n\n\u003e In Objective-C, 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.[^1][^2][^3]\n\n\u003e 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.\n\nI'm starting work on #31797 and the use of unpaired `+alloc`/`-init…` calls is generating a few warnings. I'd like to clean this up at the same time I do the ARC work.\n\n[^1]: \"But the resulting object is not yet usable.\" from [Object Allocation](https://developer.apple.com/library/archive/documentation/General/Conceptual/CocoaEncyclopedia/ObjectAllocation/ObjectAllocation.html#//apple_ref/doc/uid/TP40010810-CH7-SW1)\n[^2]: \"You must use an init... method to complete the initialization process.\" from [+alloc](https://developer.apple.com/documentation/objectivec/nsobject-swift.class/alloc)\n[^3]: \"immediately\" and \"An init message is coupled with an alloc … message in the same line of code\" from [-init](https://developer.apple.com/documentation/objectivec/nsobject-swift.class/init()?language=objc)\n\n\n\n### Proposed fix\n\n_No response_","author":{"url":"https://github.com/iccir","@type":"Person","name":"iccir"},"datePublished":"2026-05-31T18:15:24.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/31798/matplotlib/issues/31798"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7a074901-c91c-4a34-6ef8-604d2e4e3c8a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC90:20E8B8:1C82448:26E22FC:6A540153 |
| html-safe-nonce | d791aa84aa80eccd39acf0ce0d5aeb5a0566512e6e33f80212ff20a9a68bc127 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzkwOjIwRThCODoxQzgyNDQ4OjI2RTIyRkM6NkE1NDAxNTMiLCJ2aXNpdG9yX2lkIjoiNjc1MDQwOTc5MDM1MzMxMDAzNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9a308357babb2daf365e175c63039cdda0ceaf383896c49c87cdac540e633421 |
| hovercard-subject-tag | issue:4558516996 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/31798/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1e52dff771472510f6de7ef8c357716bf840ccfeecbb895a232d1e9f12fec7dc/matplotlib/matplotlib/issues/31798 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1e52dff771472510f6de7ef8c357716bf840ccfeecbb895a232d1e9f12fec7dc/matplotlib/matplotlib/issues/31798 |
| og:image:alt | Summary I mentioned the following in #21788: In Objective-C, an -init… method should always be called immediately after +alloc. Calling any other instance method on an object you just allocated bef... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iccir |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width