What does "Autoreleased without a pool in place" mean?

My application structure is as follows: the main part is written in C ++ and makes heavy use of the stream, and I develop an interface in Objective-C on top of it, if I do not execute the stream, it works fine, but I cannot disconnect, stop the stream, the user interface accidentally broken in a log that I could see after a message

__NSAutoreleaseNoPool(): Object 0x350270 of class NSCFString autoreleased with no pool in place - just leaking 

Similar messages come more than once, on googling search, I have to install NSAutoReleasePool to get rid of it, but how can it be integrated with C ++ code.

Edit: The lib core will be activated from the user interface, so I suppose its safe user interface works in the main thread, Lib creates / terminates the thread without notifying the user interface, in which case I can call AutoReleasePool in the user interface

Can anyone guide me?

+8
debugging multithreading cocoa objective-c ++
source share
2 answers

See these docs for what you need to know about multithreading with Cocoa: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html

OK, to create your application, just like yours, you need to keep two things in mind:

  • Life is simple (and sometimes necessary) when user interface controls, such as views (AppKit or UIKit), are controlled in the main thread. You can use Foundation objects and some AppKit / UIKit objects for background threads, and some Foundation objects can be used from multiple threads.
  • If you use any Cocoa objects at all in the background thread, you need to configure autorun pools for these threads.

Same:

 - (void)backgroundThreadStart { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // do stuff [pool release]; } 

This will fix your console errors, but you may have other problems that led to the actual failure you saw.

+7
source share

This means that you have implemented something without an auto-complete pool in place.

Each thread has a stack of auto-detection pools. The main thread creates a backup pool before Cocoa accesses your code and unloads after your code returns. Each object that you autorelease (whether explicitly or implicitly) enters the pool, so the pool will free it when the pool is depleted. When you create a thread, you need to create and merge the autostart pool in this thread yourself. (Or just don't autorelease anything, but it's practically impossible for any significant amount of code.)

If you ever decide to run your code under garbage collection, you will need to send the drain pool, not release , when you are done with it, so that the pool is useful. When the GC is turned on, the release and autorelease do nothing - they don't even go through. Your autoresource pool will respond to drain by popping up the garbage collector, which is the closest equivalent to releasing objects that would be in the pool.

Cocoa's Memory Programming Guide provides, among other things, additional information about autocomplete pools.

+1
source share

Source: https://habr.com/ru/post/651376/


All Articles