From c3ae4474d0fa31036981f63542fe741b3d496a0c Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Tue, 23 Jan 2018 10:45:34 -0800 Subject: [PATCH] NoCopyRendering experiment: Fix possible memory leak if image node rendering is canceled #trivial (#765) * Fix memory leak if image node rendering is canceled * Update comment --- Source/ASImageNode.mm | 5 ++--- Source/Details/ASGraphicsContext.h | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/ASImageNode.mm b/Source/ASImageNode.mm index ed56c9ceb8..b1a561eeaa 100644 --- a/Source/ASImageNode.mm +++ b/Source/ASImageNode.mm @@ -522,10 +522,9 @@ static ASDN::StaticMutex& cacheLock = *new ASDN::StaticMutex; key.didDisplayNodeContentWithRenderingContext(context, drawParameters); } - // The following `UIGraphicsGetImageFromCurrentImageContext` call will commonly take more than 20ms on an - // A5 processor. Check for cancellation before we call it. + // Check cancellation one last time before forming image. if (isCancelled()) { - UIGraphicsEndImageContext(); + ASGraphicsEndImageContext(); return nil; } diff --git a/Source/Details/ASGraphicsContext.h b/Source/Details/ASGraphicsContext.h index 0a1c80fc4b..26183d5951 100644 --- a/Source/Details/ASGraphicsContext.h +++ b/Source/Details/ASGraphicsContext.h @@ -23,6 +23,9 @@ * * The API mirrors the UIGraphics API, with the exception that forming an image * ends the context as well. + * + * Note: You must not mix-and-match between ASGraphics* and UIGraphics* functions + * within the same drawing operation. */ NS_ASSUME_NONNULL_BEGIN