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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:37:37+00:00 2026-05-18T07:37:37+00:00

I just recently made the move to Objective-C. I am doing some exercises from

  • 0

I just recently made the move to Objective-C. I am doing some exercises from Kochan’s Programming in Objective-C 2.0. On this particular exercise, I am asked to modify the print method with and optional argument:

-(void)print{
  NSLog(@" %i/%i ", numerator, denominator);
}

For this I simply created another print method that would take a BOOL argument and modified the existing print method as follows:

-(void)print{
  [self printReduced:FALSE];
}
-(void)printReduced:(BOOL)r{
  if(r){
    [self reduce];
  }
  NSLog(@" %i/%i ", numerator, denominator);
}

But for the last part of the exercise, I am supposed to use that BOOL to determine if the Fraction should be reduced or not (no problem testing the flag), but when reduced I am not supposed to modify the original object. For this I allocated a new Fraction object inside the printReduced method and released it before the end of the method too:

-(void)printReduced:(BOOL)r{
  Fraction *printingFraction = [[Fraction alloc] init];
  [printingFraction setTo:numerator over:denominator];
  if(r){
    [printingFraction reduce];
  }
  NSLog(@" %i/%i ",[printingFraction numerator], [printingFraction denominator]);
  [printingFraction release];
}

My question is: Is it right to create and release objects whithin a given method this way? This seems to do the work just fine without modifying the original Fraction, but is this the right approach?

  • 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-18T07:37:38+00:00Added an answer on May 18, 2026 at 7:37 am

    This is correct. Whenever you ‘alloc’ an object, you own it. Before it goes out of scope (the end of the method in this case), you must relinquish ownership, a release in this case.

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

Sidebar

Related Questions

I recently made the move from Linux development to Windows development. And as much
Having made the jump just recently from XEmacs to GNU Emacs, I'm really loving
I just recently got my first mac. I do lots of programming on windows
I've just recently upgraded to SQL Server 2008 from 2005 and when I attempt
My site is rather extensive, and I just recently made the switch to PHP5
I recently made the insanely long overdue switch from tcsh to bash. The only
I have an iPhone app that is using CoreData. I recently made some minor
I just recently installed the MVC beta. However, I assumed because the versioning numbers
I just recently noticed Dictionary.TryGetValue(TKey key, out TValue value) and was curious as to
I just recently installed Winamp Song Requester wich is a Winamp web song requester

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.