summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorritsuka <[email protected]>2015-05-12 13:14:29 +0000
committerritsuka <[email protected]>2015-05-12 13:14:29 +0000
commit792e8a595b395eb98e9ce8f9bd0dd1304644e42f (patch)
treea9c7ab5a62f4af5c18296f7222c0210c848b7952
parent7a4983f7bb43608fc6d84ffa26007511d928bf9f (diff)
MacGui: limit the preview images cache to ~ the size of 60 1080p images.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7171 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--macosx/HBPreviewGenerator.m14
1 files changed, 10 insertions, 4 deletions
diff --git a/macosx/HBPreviewGenerator.m b/macosx/HBPreviewGenerator.m
index 345c574c8..e1cf20e26 100644
--- a/macosx/HBPreviewGenerator.m
+++ b/macosx/HBPreviewGenerator.m
@@ -15,7 +15,7 @@
@interface HBPreviewGenerator ()
-@property (nonatomic, readonly) NSMutableDictionary *picturePreviews;
+@property (nonatomic, readonly) NSCache *picturePreviews;
@property (unsafe_unretained, nonatomic, readonly) HBCore *scanCore;
@property (unsafe_unretained, nonatomic, readonly) HBJob *job;
@@ -32,7 +32,11 @@
{
_scanCore = core;
_job = job;
- _picturePreviews = [[NSMutableDictionary alloc] init];
+
+ _picturePreviews = [[NSCache alloc] init];
+ // Limit the cache to 60 1080p previews, the cost is in pixels
+ _picturePreviews.totalCostLimit = 60 * 1920 * 1080;
+
_imagesCount = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imagesSettingsDidChange) name:HBPictureChangedNotification object:job.picture];
@@ -62,7 +66,7 @@
// The preview for the specified index may not currently exist, so this method
// generates it if necessary.
- CGImageRef theImage = (__bridge CGImageRef)(self.picturePreviews)[@(index)];
+ CGImageRef theImage = (__bridge CGImageRef)([self.picturePreviews objectForKey:@(index)]);
if (!theImage)
{
@@ -75,7 +79,9 @@
deinterlace:deinterlace];
if (cache && theImage)
{
- (self.picturePreviews)[@(index)] = (__bridge id)theImage;
+ // The cost is the number of pixels of the image
+ NSUInteger previewCost = CGImageGetWidth(theImage) * CGImageGetHeight(theImage);
+ [self.picturePreviews setObject:(__bridge id)(theImage) forKey:@(index) cost:previewCost];
}
}
else