Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8581209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:59:34+00:00 2026-06-11T20:59:34+00:00

On one hand, I’m just curious. On the other, I have to count somehow

  • 0

On one hand, I’m just curious.

On the other, I have to count somehow the amount of images created (to trigger cleanup at some quantity). Unfortunately memory warnings notify me too late, the app gets terminated before I have any chance to react, so thatswhy I want to work this issue around.

I could scatter around my project with a global counter, that increments before I make any UIImage operation, but obviously this is exactly what I want to avoid, that would result in an unmaintainable design.

So I was thinking about subclass UIImage initializers (some kind of MYImage class), than use MYImage troughout the project, but UIImageView’s would use UIImages anyway (maybe I can set UIImageView’s setImage method, but I bet UIKit uses actual _image instance variable at many cases).

The best would be to count pixels amount from UIImage sizes, so I could flush image memory above a given pixelcount.

Any notification? Something trough categories? Or some kind of NSObject KVO observing (with literal checkings on class/method names)? Do you have ideas/experiences?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:59:35+00:00Added an answer on June 11, 2026 at 8:59 pm

    There a a lot of ways you could accomplish this. One way would be to override one (or more) of the image creation methods in a subclass, get the size of the image created, and add that to a user default to keep track of the cumulative sizes of all the images. For example, I overrode imageNamed like this:

    @implementation RDImage
    
    +(UIImage *)imageNamed:(NSString *) name {
        UIImage *anImage = [super imageNamed:name];
        double oldSize = [[NSUserDefaults standardUserDefaults] doubleForKey:@"SizeAsWxH"];
        [[NSUserDefaults standardUserDefaults] setDouble:(anImage.size.width * anImage.size.height) + oldSize forKey:@"SizeAsWxH"];
        if ([[NSUserDefaults standardUserDefaults] doubleForKey:@"SizeAsWxH"] > 6912) {
            NSLog(@"Too big -- do something");
        }
        return anImage;
    }
    

    In the applicationDidFinishLaunchingWithOptions: method, I set the value of that key to zero.

    In the view controller when I create an image, I just use my class to make a new one:

    UIImage *anImage = [RDImage imageNamed:....
    

    Another way would be to override the setImage: method of UIImageView, and do the same kind of thing inside that method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have on one hand a complex, multi-threaded application, and on the other a
I have a Coda slider on one webpage (hand-crafted, not using the plugin, but
On one hand, I know that the advisable usage of Properties is to have
On the one hand there is http://ckfinder.com/ CKFinder or the people behind it have
im messing with the encodings. For one hand i have a url that is
On one hand I have coded a function in Scala that reads Excel Files.
On the one hand, we are encouraged to just create fields, and not encrust
On one hand, a tuple is versatile, but on the other, can be less
For our database development we have on one hand a full schema DDL script,
I have a class where on the one hand, it feels right to return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.