It is always being asked in an interview how many maximum threads we can run in ios iPhone programming simultaneously in NSOperationQueue? But Is there any limit to create NSOperationQueue in iOS?
Asked
Active
Viewed 165 times
1
-
I think `NSOperationQueue` or `OperationQueue` has no limitation of how much instances can be created. All it does is dispatching threads along with blocks(closures) according to CPU count in the current system or hardware. If there is/are free core/cores, there will be parallel dispatching and serial when enough threads are queued and all cores are busy. You can relate with performance intensive applications such as Game apps where tens to thousands of threads might be queued plus some created by other apps and iOS itself. – Cosmos Man Jul 20 '18 at 10:02
-
if i am not wrong then You can have only one thread as main thread. while you have no limit for background threads. – Prashant Tukadiya Jul 20 '18 at 10:29
-
Possible duplicate of [Default value of maxConcurrentOperationCount for NSOperationQueue](https://stackoverflow.com/questions/14995801/default-value-of-maxconcurrentoperationcount-for-nsoperationqueue) – Kamran Jul 20 '18 at 10:50
-
Also see https://stackoverflow.com/questions/32023212 – Kamran Jul 20 '18 at 10:50
1 Answers
1
I am answering your tricky part of the question.
Is there any limit to create NSOperationQueue in iOS?
Logically there is a limit but that depends upon device memory.
NSOperationQueue is a class so if you create an object it's gonna hold some memory and if you don't release that object one time it's gonna be out of memory or your application will get killed by OS.
Try this it gives me 32 bytes.
#import <malloc/malloc.h>
.....
NSOperationQueue *test = [[NSOperationQueue alloc] init];
NSLog(@"Size of %@: %zd bytes", NSStringFromClass([NSOperationQueue class]), malloc_size((__bridge const void *) test));
Now every different model of the iOS device has different memory limit for application to access. So if your device has 100mb limit for an app. Now You know how many NSOperationQueue you can create.

Ravi Prakash
- 1,078
- 1
- 8
- 14