Skip to content

MacOS: missing Obj-C autorelease pool handling #58

@kikaxa

Description

@kikaxa

Most functions end up using native apis which create autorelease objects.
These objects would be effectively "leaked" if run through async++.

The thread pool/loop needs local per-iteration pool to match user expectations(or lack of).

sample Qt pool handling:

#ifdef __APPLE__
// Use the direct runtime interface to manage autorelease pools, as it
// has less overhead then allocating NSAutoreleasePools, and allows for
// a future where we use ARC (where NSAutoreleasePool is not allowed).
// https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support
extern "C" {
    void *objc_autoreleasePoolPush(void);
    void objc_autoreleasePoolPop(void *pool);
}
    #define AUTORELEASE_THREAD_GUARD() auto poolDone = ScopedDefer([pool = objc_autoreleasePoolPush()](){ objc_autoreleasePoolPop(pool); });
#else
    #define AUTORELEASE_THREAD_GUARD()
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions