mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Implement -reclaimMemory API and switch to manually controlled content clearing.
ASDisplayNode and several subclasses had previously cleared memory-heavy objects like the backing store and text layout manager when the node's view or layer is removed from a visible heirarchy. This works great in any system that uses a "working range", where exiting the range removes the node from the hierarchy and reclaiming memory at that time is important. However, for standard UIViewController patterns (unused in Paper), this behavior causes highly undesirable thrashing (leading to visible flashes & wasteful re-rendering of content). After this change, node subclasses should implement -reclaimMemory if they need to perform any other cleanup besides backing store destruction when they leave a working range or other scenario where memory reduction is valuable. To trigger this behavior, calling code should use -recursivelyReclaimMemory. r=nadi
This commit is contained in:
@@ -194,17 +194,6 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
fminf(ceilPixelValue(renderSizePlusShadowPadding.height), constrainedSize.height));
|
||||
}
|
||||
|
||||
- (void)willEnterHierarchy
|
||||
{
|
||||
CALayer *layer = self.layer;
|
||||
if (!layer.contents) {
|
||||
// This can happen on occasion that the layer will not display unless this
|
||||
// set.
|
||||
[layer setNeedsDisplay];
|
||||
}
|
||||
[super willEnterHierarchy];
|
||||
}
|
||||
|
||||
- (void)displayDidFinish
|
||||
{
|
||||
[super displayDidFinish];
|
||||
@@ -217,16 +206,13 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
[self _invalidateRenderer];
|
||||
}
|
||||
|
||||
- (void)didExitHierarchy
|
||||
- (void)reclaimMemory
|
||||
{
|
||||
// We nil out the contents and kill our renderer to prevent the very large
|
||||
// We discard the backing store and renderer to prevent the very large
|
||||
// memory overhead of maintaining these for all text nodes. They can be
|
||||
// regenerated when layout is necessary.
|
||||
self.contents = nil;
|
||||
|
||||
[super reclaimMemory]; // ASDisplayNode will set layer.contents = nil
|
||||
[self _invalidateRenderer];
|
||||
|
||||
[super didExitHierarchy];
|
||||
}
|
||||
|
||||
- (void)didLoad
|
||||
|
||||
Reference in New Issue
Block a user