mirror of
https://github.com/TextureGroup/Texture.git
synced 2026-04-07 19:17:39 +00:00
Remove background deallocation helper code (#1890)
* Remove background deallocation helper code Last use removed in Texture with #1840, now PINS no longer uses it either. Less OOMs is so nice. * remove methods from docs
This commit is contained in:
@@ -27,67 +27,6 @@ static void runLoopSourceCallback(void *info) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma mark - ASDeallocQueue
|
||||
|
||||
@implementation ASDeallocQueue {
|
||||
std::vector<CFTypeRef> _queue;
|
||||
AS::Mutex _lock;
|
||||
}
|
||||
|
||||
+ (ASDeallocQueue *)sharedDeallocationQueue NS_RETURNS_RETAINED
|
||||
{
|
||||
static ASDeallocQueue *deallocQueue = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
deallocQueue = [[ASDeallocQueue alloc] init];
|
||||
});
|
||||
return deallocQueue;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
ASDisplayNodeFailAssert(@"Singleton should not dealloc.");
|
||||
}
|
||||
|
||||
- (void)releaseObjectInBackground:(id _Nullable __strong *)objectPtr
|
||||
{
|
||||
NSParameterAssert(objectPtr != NULL);
|
||||
|
||||
// Cast to CFType so we can manipulate retain count manually.
|
||||
const auto cfPtr = (CFTypeRef *)(void *)objectPtr;
|
||||
if (!cfPtr || !*cfPtr) {
|
||||
return;
|
||||
}
|
||||
|
||||
_lock.lock();
|
||||
const auto isFirstEntry = _queue.empty();
|
||||
// Push the pointer into our queue and clear their pointer.
|
||||
// This "steals" the +1 from ARC and nils their pointer so they can't
|
||||
// access or release the object.
|
||||
_queue.push_back(*cfPtr);
|
||||
*cfPtr = NULL;
|
||||
_lock.unlock();
|
||||
|
||||
if (isFirstEntry) {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.100 * NSEC_PER_SEC)), dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
|
||||
[self drain];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)drain
|
||||
{
|
||||
_lock.lock();
|
||||
const auto q = std::move(_queue);
|
||||
_lock.unlock();
|
||||
for (CFTypeRef ref : q) {
|
||||
// NOTE: Could check that retain count is 1 and retry later if not.
|
||||
CFRelease(ref);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation ASAbstractRunLoopQueue
|
||||
|
||||
- (instancetype)init
|
||||
|
||||
Reference in New Issue
Block a user