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 974691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:28:22+00:00 2026-05-16T03:28:22+00:00

In my code, I use a singleton object as a central point in my

  • 0

In my code, I use a singleton object as a central point in my app to load and cache images the app frequently needs, so I don’t have to do resource-intensive memory allocation each time I load an image.

But there are times during the execution of my app where memory usage gets intense and I would like to release the cached image data. Currently, I’m just releasing the UIImage instances from my singleton when I get a memory warning.

I would prefer, however, to be able to release the entire singleton object. Is that possible? If so, how?

  • 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-05-16T03:28:23+00:00Added an answer on May 16, 2026 at 3:28 am

    Of course it is. Although it’s rather likely that the memory usage of this object is negligible compared to the images.

    By the nature of a singleton, you need to have an accessor for it, where you will create it if it does not currently exist:

    + (MySingletonClass*) mySingleton
    {
        if ( mySingleton == nil )
        {
            mySingleton = [[MySingletonClass alloc] init];
        }
    
        return mySingleton;
    }
    

    You just need to add another that you call when you want to destroy it:

    + (void) destroyMySingleton
    {
        [mySingleton release];
        mySingleton = nil;
    }
    

    If you keep references to it around elsewhere you’ll have trouble; don’t do that. If you access from multiple threads you’ll need to synchronize. Otherwise, it’s pretty straightforward — the getter will recreate when you next need it.

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

Sidebar

Related Questions

All the singleton patterns I have seen use a reference to the object to
In the Singleton pattern why is that we have to use a static object
I have the following code: use Imager::Screenshot 'screenshot'; my $img = screenshot(hwnd => 'active',
I know this code use to work, I must have accidentally changed something when
I have the following code: use strict; function isDefined(variable) { return (typeof (window[variable]) ===
I have the following test code use Data::Dumper; my $hash = { foo =>
I have a static class in my ASP.NET app that I use to hold
I have problem with cache in my asp.net mvc3 application. My code using System.Web.Caching;
I have a singleton data manager object that manages the connection to a web
Using the following code: use LWP::Simple; my $url= http://example.com; my $html= get $url; I

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.