The Artima Developer Community
Sponsored Link

Python Buzz Forum
Threads and PyObjc

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Victor Ng

Posts: 112
Nickname: victorng
Registered: Aug, 2003

Victor Ng programs Python for money, but he'd be programming Python anyway if he was a bum.
Threads and PyObjc Posted: Oct 19, 2003 9:41 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Victor Ng.
Original Post: Threads and PyObjc
Feed Title: Victor Ng's Weblog
Feed URL: https://blog.crankycoder.com/feed/atom/
Feed Description: Python Feed
Latest Python Buzz Posts
Latest Python Buzz Posts by Victor Ng
Latest Posts From Victor Ng's Weblog

Advertisement

Well this was entirely obvious once I sat down and tried to remember the tiny bits of Objective-C I used to know.

When you create threads in PyObjc you have to be careful to also create an instance of NSAutoreleasePool in your thread's run() loop or else you'll get an irritating memory leak.

Exact rules on when/why/how to do this from the Foundation class docs:

NSAutoreleasePool


If you are making Cocoa calls outside of the Application KitÂ’s main thread, however, you need to create your own autorelease pool. This is the case if you are a Foundation-only application or if you detach a thread. If your application or thread is long-lived and potentially generates a lot of autoreleased objects, you should periodically destroy and create autorelease pools (like the Application Kit does on the main thread); otherwise, autoreleased objects accumulate and your memory footprint grows. If your detached thread does not make Cocoa calls, you do not need to create an autorelease pool.

Hmm...

Now that I'm writing this down - I recall something about Cocoa being very not-threadsafe. The suggested way of handling updates to Cocoa using threads was something like posting messages into an event queue or something like that.

Argh... anyone care to point me in the right direction here or am I suffering from false memories again? Is Cocoa threadsafe if I'm doing updates to NSTextView instances from multiple threads?

Addendum: Yeah - there are issues. Note to self - read this.

victor "i hate mozilla this weekend" ng

Read: Threads and PyObjc

Topic: Now that's a swell icon Previous Topic   Next Topic Topic: IDEs and editors

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use