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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:24:40+00:00 2026-06-13T14:24:40+00:00

// targ_url is passed in as an address to a NSString pointer. – (long)

  • 0
// targ_url is passed in as an address to a NSString pointer.

- (long) analyse_scan_result : (NSString *)scan_result  target_url : (NSString **)targ_url

{

    NSLog (@" RES analyse string : %@", scan_result);

    NSRange range = [scan_result rangeOfString : @"http://"
                                 options       : NSCaseInsensitiveSearch
                     ];

    // **** The following retain is the first retain 
    // **** statement in this method.

    if (range.location == NSNotFound)
    {
        *targ_url = @"";
       [*targ_url retain];
        NSLog(@" FND string not found");
        return 0;
    }

    NSString *sub_string = [scan_result substringFromIndex : range.location];

    range = [sub_string rangeOfString : @" "];

    if (range.location != NSNotFound) {
        sub_string = [sub_string substringToIndex : range.location];         
    }

    NSLog(@"FND sub_string = %@", sub_string);

    *targ_url = sub_string;

    // ** The following retain is the second retain
    // ** statement in this method.

    [*targ_url retain];

    return [*targ_url length];

}

This question is similar and related to the one I asked earlier (which seems to be satisfactorily solved). Again, the above method only works after a retain statement is added. There are 2 added above, but only one is executed at any given time.

What the routine does is to find a “http://” string from a barcode scanner output and return it. My question is are the retain statements necessary or appropriate ?

Hope somebody knowledgable could help…

  • 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-13T14:24:41+00:00Added an answer on June 13, 2026 at 2:24 pm

    TL;DR

    Do not return owned object values by reference.

    Explanation:

    By convention, objects returned by reference (or even by value) are not owned unless the method specifically states this. If the method name contains copy or new then it is expected to provide an owned reference, otherwise the reference count is considered to be irrelevant.

    For instance, Cocoa methods that return an NSError by reference return an autoreleased NSError which you are not expected to release.

    What this means is, you can do either, as long as you indicate what you are doing via the method name. You probably just want to return an autoreleased reference and let the caller decide whether they want to keep holding on to it or not.

    Apparently, Apple feels you should not return owned values by reference, according to this document:

    https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html

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

Sidebar

Related Questions

class A { pointer* p; template<class T> f(T a) { p->property()->doSomething(a); // doSomething is
Normally for a string to object is converted as follows. var obj:object=getChildByName(string); And we
if (url_leng) { NSString *open_string; if (g_system_status.language_code == 0) open_string = @Open; else if
Let's assume we have a template function foo: template<class T> void foo(T arg) {
function doSomething(e) { var targ; if (!e) var e = window.event; //<<<< what does
(using http://code.google.com/p/svgweb/ ) window.onsvgload = function() { function onEnter(e) { var targ; if (!e)
I had three drop down menus. Depending on items selected on two lists, the
I am trying to build some kernel modules I added to my Ubuntu source
I'm doing the following: if [ -f $FILE ] ; then echo "File exists"
I'm having trouble compiling wmii v3.9.2 on Fedora 15; Here's the interesting part (things

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.