Objective-C block will not be released for background only applications

I have an application that works only in the background (by specifying LSBackgroundOnlyin the info.plist file). The problem is that all the blocks that I run in parallel queues are not issued. Code runs in a memory-driven environment - GC is not involved.

The code (simplified) is as follows. Blubber is just some kind of dummy class that contains NSDate for testing. In addition, it overwrites retain, releaseand deallocto perform some logging:

NSOperationQueue *concurrentQueue = [[NSOperationQueue alloc] init];
[concurrentQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount];

Blubber *aBlubber = [[Blubber alloc] init]; 
aBlubber.aDate = [NSDate date];

[concurrentQueue addOperationWithBlock:^{       
NSAutoreleasePool *blockPool = [[NSAutoreleasePool alloc] init];
    NSDate *test = [aBlubber aDate];
    NSLog(@"Block DONE");
    [blockPool release];    
}];

[aBlubber release];

[concurrentQueue release];

(.. ) , , , ( ). backgorund HID USB, , .

runloop - , ?

( , , , . "" " ", "skyrocketing" .)

+3
2

"" autorelease - , , (, ) .

, , ... :

...
//When no events are coming in (i.e. the user is away from their computer), the runloop doesn't iterate, and we accumulate autoreleased objects
[[NSTimer scheduledTimerWithTimeInterval:60.0f target:self selector:@selector(kickRunLoop:) userInfo:nil repeats:YES] retain];
...
- (void) kickRunLoop:(NSTimer *)dummy
{
// Send a fake event to wake the loop up.
[NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined
                                    location:NSMakePoint(0,0)
                               modifierFlags:0
                                   timestamp:0
                                windowNumber:0
                                     context:NULL
                                     subtype:0
                                       data1:0
                                       data2:0]
         atStart:NO];
}
+2

, , , . . , :

[concurrentQueue addOperationWithBlock:[[^{       
    NSAutoreleasePool *blockPool = [[NSAutoreleasePool alloc] init];
    NSDate *test = [aBlubber aDate];
    NSLog(@"Block DONE");
    [blockPool release];    
}copy]autorelease]];

: http://gkoreman.com/blog/2011/02/27/blocks-in-c-and-objective-c/

0

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


All Articles