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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:55:26+00:00 2026-05-24T01:55:26+00:00

I am testing the following code below. ffv is declared in the interface file.

  • 0

I am testing the following code below. ffv is declared in the interface file.

ffv = [[FullFunctionView alloc] initWithFrame:self.view.bounds];
NSLog(@"%i", [ffv retainCount]);  // prints 1
[self.view insertSubview:ffv belowSubview:switchViewsBtn];
NSLog(@"%i", [ffv retainCount]);  // prints 2
[ffv release]; // you can release it now since the view has ownership of ffv
NSLog(@"%i", [ffv retainCount]);  // prints 1

if (ffv == nil)
    NSLog(@"ffv is nil");

// "ffv is nil" is not printed

[ffv testMethod]; // "test method called" is printed

this is my [ffv testMethod] implementation

- (void)testMethod
{
    NSLog(@"test method called");
}

What I deduce in this case is that even if you release an object with retain count 2, you lose ownership of that object however, the reference is still kept.

Now, my question are:

  1. Is my deduction correct?
  2. Is there anything else important that can be deduced from this?
  3. What are the complications caused by still keeping (using) ffv and calling methods from ffv? (My opinion is that this is ok since the view will always own ffv and won’t release it until someone calls viewDidUnload. And as long as I don’t pass ffv’s reference to other objects.)
  • 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-24T01:55:27+00:00Added an answer on May 24, 2026 at 1:55 am

    1) Is my deduction correct?

    Your deduction is correct. The Memory Management Programming Guide explains that each object has one or many owners. You own any object you create using any method starting with alloc, new, copy, or mutableCopy. You can also take ownership of an object using retain. When you’re done with an object, you must relinquish ownership using release or autorelease.

    Releasing the object doesn’t change the value of any variables that reference that object. Your variable contains the object’s memory address until you reassign it, no matter what retain count the object has. Even if the object’s retain count goes to zero, causing the object to get deallocated, your variable will still point at that same address. If you try to access the object after it’s been deallocated, your app will normally crash with EXC_BAD_ACCESS. This is a common memory management bug.

    2) Is there anything else important that can be deduced from this?

    Nothing comes to mind.

    3) What are the complications caused by still keeping (using) ffv and calling methods from ffv? (My opinion is that this is ok since the view will always own ffv and won’t release it until someone calls viewDidUnload. And as long as I don’t pass ffv’s reference to other objects.)

    When you call release, you are telling the Objective C runtime that you no longer require access to the object. While there may be many cases like this one in which you know the object will still exist, in practice you really shouldn’t access an object after calling release. You’d just be tempting fate and setting yourself up for future bugs.

    I personally don’t like peppering my code with release statements, because I don’t trust myself to remember them 100% of the time. Instead, I prefer to autorelease my variables as soon as I allocate them like this:

    ffv = [[[FullFunctionView alloc] initWithFrame:self.view.bounds] autorelease];
    

    This guarantees that ffv will exist at least until the end of the method. It will get released shortly thereafter, typically before the next iteration of the run loop. (In theory this could consume excessive memory if you’re allocating a large number of temporary objects in a tight loop, but in practice I’ve never encountered this case. If I ever do, it will be easy to optimize.)

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

Sidebar

Related Questions

I am learning PHP PEAR and testing the following code. However when I login,
I'm running the following code on a file that has been uploaded to this
the code here below: #!/usr/bin/env python import wx class MyForm(wx.Frame): def __init__(self): wx.Frame.__init__(self, None,
I am having difficulties testing window.setInterval function in my Javascript file. Below is the
The following code-behind binding works for the SmartFormView user control: View: <UserControl x:Class=CodeGenerator.Views.PageItemManageSettingsView xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
VS C# 2005 I am using the code below to upload a file to
I used the following code to store the file on Internal Storage in Application
While testing the below SQL code for another stackoverflow answer , I got the
I am testing against the following test document: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC
I am trying to do some Cucumber testing like the following: Given I am

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.