Clang Static Analyzer - Bug Report

Discussion in 'iOS Programming' started by mpramodjain, Mar 11, 2011.

  1. mpramodjain, Mar 11, 2011
    Last edited: Mar 11, 2011

    mpramodjain macrumors regular

    Joined:
    Nov 20, 2008
    Location:
    Banglore
    #1
    Hi,

    I had the following method returning an object allocated.

    Code:
    -(UILabel*)getCustomUILabelObject{
    UILabel *lLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,0,320,400)];
    return lLabel;
    }
    
    -(void)loadView{
    
    UILabel *lCustomUILabel=[self getCustomUILabelObject];
    [lCustomUILabel release];
    lCustomUILabel=nil;
    }
    
    So while using the Clang Static Analyzer , It is reporting following bug at return value.

    leak returning value.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    1) This forum has nothing to do with Apple. There is not point filling "Bug Reports" here.

    2) That is not a bug. The well defined memory management conventions for Cocoa are that methods return autoreleased objects. So getCustomUILabelObject should return an autoreleased UILabel. This is not what you are doing.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    The compiler should also complain that UILable is undeclared. Do you know why?
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Clang reports on any violations of the Cocoa naming conventions. Methods that return retained objects must be named with new or create in them. You've named your method with get in it so your method should follow the get rule, which it does not.

    Change the method name to newCustomUILabelObject and Clang won't object.
     
  5. mpramodjain thread starter macrumors regular

    Joined:
    Nov 20, 2008
    Location:
    Banglore
    #5
    Yeh.. thats a typo mistake...
     

Share This Page