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

  • Home
  • SEARCH
  • 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 8270659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:38:50+00:00 2026-06-08T06:38:50+00:00

I am working on a project which is non-ARC. The project has a singleton

  • 0

I am working on a project which is non-ARC. The project has a singleton class which is use like a global functions class.

Everything works fine. Except for the following problems:

  • Added a class with ARC
  • When the singleton class is accessed from the ARC based class, it works for the first time
  • Probably it is releasing the singleton class and further calls to the singleton class crashes the app with message “message sent to de-allocated instance”

I can imagine that the ARC enabled class is kind of releasing the singleton object.

How can i overcome this?

Edit: Singleton Class initializer GlobalFunctions.m

#import "GlobalFunctions.h"
#import <CoreData/CoreData.h>
#import "UIImage+Tint.h"
#import "Reachability.h"
#if !TARGET_IPHONE_SIMULATOR
    #define Type @"Device"
#else
    #define Type @"Simulator"
#endif

@implementation GlobalFunctions

#pragma mark {Synthesize}
@synthesize firstLaunch=_firstLaunch;
@synthesize context = _context;

#pragma mark {Initializer}
static GlobalFunctions *sharedGlobalFunctions=nil;


- (UIColor *)UIColorFromRGB:(NSInteger)red:(NSInteger)green:(NSInteger) blue {
    CGFloat nRed=red/255.0; 
    CGFloat nBlue=green/255.0;
    CGFloat nGreen=blue/255.0;    
    return [[[UIColor alloc]initWithRed:nRed green:nBlue blue:nGreen alpha:1] autorelease];
}

#pragma mark {Class Intialization}
+(GlobalFunctions *)sharedGlobalFunctions{
    if(sharedGlobalFunctions==nil){
       // sharedGlobalFunctions=[[super allocWithZone:NULL] init];
        sharedGlobalFunctions=[[GlobalFunctions alloc] init]; //Stack Overflow recommendation, does'nt work
        // Custom initialization
        /* 
         Variable Initialization and checks
        */
        sharedGlobalFunctions.firstLaunch=@"YES";   
        id appDelegate=(id)[[UIApplication sharedApplication] delegate];        
        sharedGlobalFunctions.context=[appDelegate managedObjectContext];
    }
    return sharedGlobalFunctions;
}

-(id)copyWithZone:(NSZone *)zone{
    return self;
}
-(id)retain{
    return self;
}
-(NSUInteger) retainCount{
    return NSUIntegerMax;
}
-(void) dealloc{
    [super dealloc];
    [_context release];
}
@end

GlobalFunctions.h

#import <Foundation/Foundation.h>

@interface GlobalFunctions : NSObject<UIApplicationDelegate>{
    NSString *firstLaunch;

}

+(GlobalFunctions *)sharedGlobalFunctions; //Shared Object 
#pragma mark {Function Declarations}
-(UIColor *)UIColorFromRGB:(NSInteger)red:(NSInteger)green:(NSInteger) blue; // Convert color to RGB

#pragma mark {Database Objects}
@property (nonatomic,retain) NSManagedObjectContext *context;


@end

Edit:

Tried using [[GlobalFunctions alloc] init] as Anshu suggested. But still the app crashes with message “sent to deallocated instance”

  • 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-08T06:38:53+00:00Added an answer on June 8, 2026 at 6:38 am

    First, remove the copyWithZone:, retain and retainCount methods; they are useless in a singleton.

    Secondly, that dealloc method is wrong; [super dealloc] must always be the last statement.

    The problem is your singleton itself; you override retain to do nothing, but don’t override release. The ARC’d class is likely calling retain at the beginning of a scope and release at the end. Since the singleton’s release still actually decrements the retain count, the singleton is deallocated.

    Remove the various methods as mentioned above and it should just work.

    Note that your GlobalFunctions class shouldn’t be declared as implementing <UIApplicationDelegate> as it is not the app’s delegate. Also, having two means of grabbing the same managed object context is odd (but not fatal).

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

Sidebar

Related Questions

Well I am working on a non-ARC project, but use Philipp Kyeck's socketio library
Can anyone help me find an up-to-date, working ATL project which has a main
I'm working on a project which needs to use youtube api. The html and
A project I'm working on uses a non-standard distribution system, which internally downloads and
I'm working an project (pure hobby, Sharping my skills) which has one unified back-end
I am working on a project in php which has a 'toolkit' folder/repository of
I'm working on a project in Tableau (which uses functions very similar to Excel,
Iam working on a project which involves writing a Mork File (Mork is a
I'm working on a project which contains several slave nodes and one master node.
I'm working on a project which involves two processes, let them be A and

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.