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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:24:22+00:00 2026-05-13T13:24:22+00:00

I have an iPhone application which has some methods to gather information from the

  • 0

I have an iPhone application which has some methods to gather information from the web and which then creates an object, which holds this information as properties (lets say I’ll get objects of type x). Since I might need those kind of objects from various points within the application, I put the method to create one instance of the object into a single implementation file and called that file “GetDetails.m” (+ h). In this method I exclusively have class methods*, (amongst those my method to create object x) which create the Object and fill its properties with the information that the method gathers from the web.

+ (ObjX *)getObjectX:(NSString *key) withParameters:(NSArray *)parameters;

Within this method my ObjX is filled with information…

ObjX *objectX = [[ObjX alloc] init];
(...)
objectX.name = gatheredName;  // etc
(...)
return objectX;

So my class method is invoked at several points from within the app (btw. from within a separate thread):

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ObjX *myObject;
myObject = [GetDetails getObjectX:@"09384f9a" withParameters:nil];
[self performSelectorOnMainThread:@selector(doStuffWithNewObject:) withObject:myObject waitUntilDone:NO];
[pool release];

I can’t get rid of the feeling that this approach is not optimal. The Xcode analyzer also tells me that there might be a potential leak on return objectX.

Maybe someone could point me to the right direction and how I should do the splitting up of functionalities in general.

*It also doesn’t have an init and dealloc method, no ivars, no instance methods…


Edit

Okay, obviously most see no release for the object, so I guess I was not clear with that – the Object will be released later after it’s assigned to a property of a view.
Still, I see that it’s practice to return an autoreleased object. Unfortunately, my App crashes when I do that. Maybe it’s because of I am running that whole processing within a separate thread / autorelease pool?
I will test some configurations and will let you know how it went.

  • 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-13T13:24:22+00:00Added an answer on May 13, 2026 at 1:24 pm

    The analyzer will be giving you grief because you do not autorelease your objects when you return them. The usual method would look as follows:

    ObjX *objectX = [[ObjX alloc] init];
    ...
    return [objectX autorelease];
    

    Now, as far as implementation goes, this sounds like a place to use categories. I would do something like this:

    GetDetails_ObjX.h

    @interface ObjX (GetDetails)
    + (ObjX *)objXWithIdentifier:(NSString *)ident parameters:(NSArray *)params;
    @end
    

    GetDetails_ObjX.m

    @implementation ObjX (GetDetails)
    + (ObjX *)objXWithIdentifier:(NSString *)ident parameters:(NSArray *)params
    {
        ObjX *objectX = [[ObjX alloc] init];
        ...
        return [objectX autorelease];
    }
    @end
    

    GetDetails.h

    #import "GetDetails_ObjX.h"
    #import "GetDetails_ObjY.h"
    ...
    

    This setup could be used as follows:

    #import "GetDetails.h"
    ...
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    ObjX *myObject;
    myObject = [ObjX objectXWithIdentifier:@"09384f9a" parameters:nil];
    [self performSelectorOnMainThread:@selector(doStuffWithNewObject:)
                           withObject:myObject
                        waitUntilDone:NO];
    [pool release];
    

    A couple of notes, here:

    1. I used the method signature objXWithIdentifier... because I’m not sure what the @”09384f9a” string actually is. If it is an address, you would use objXWithAddress.... If it is a reference number, you would use objXWithReferenceNumber..., etc.

    2. I had to look this up to be sure. The performSelectorOnMainThread... method retains its argument, so there is no concern about the object being released before the method gets called on the main thread.

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

Sidebar

Related Questions

I have two projects, a Cocoa iPhone application and a static library which it
I have a webview in my iPhone application, and I also have some html
I have an application that works some what similar to how iPhone's Contact application
I have an iPhone application with a settings.bundle that handles various settings for my
I have created an iPhone application based on an OpenGL view. Now I would
I have worked on iPhone application but not aware of the formalities to submit
In my iPhone application I have a table view. When user taps any row,
Does anyone have any suggestions as to how to version an iphone application aside
I have included <zlib.h> in my iphone application and the source code I was
AVFoundation.framework is not where the documentation says it should be. I have iPhone SDK

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.