Is there any kind of memory-zeroing objective-c undertakes on my behalf when I first allocate a class instance? I see a lot of objective-c code out there that presumes their outlets are nil by default. If I do the same am I basing such behavior on false pretenses?
            Asked
            
        
        
            Active
            
        
            Viewed 344 times
        
    4
            
            
         
    
    
        AnthonyWJones
        
- 187,081
- 35
- 232
- 306
 
    
    
        fbrereto
        
- 35,429
- 19
- 126
- 178
2 Answers
8
            
            
        Yes, all alloced objects are zeroed out. See NSObject alloc documentation. It is guaranteed by the language so it is perfectly safe to do so and in fact setting the members to 0 yourself would be redundant.
 
    
    
        Peter N Lewis
        
- 17,664
- 2
- 43
- 56
 
    
    
        Jon Steinmetz
        
- 4,104
- 1
- 23
- 21
8
            NSAllocateObject returns a block of memory large enough to include all the ivars in the class; its isa pointer is set to the class, and the rest of the block is filled with 0. +[NSObject alloc] calls +[NSObject allocWithZone:] which then calls NSAllocateObject internally.
 
    
    
        Quuxplusone
        
- 23,928
- 8
- 94
- 159
 
    
    
        rpetrich
        
- 32,196
- 6
- 66
- 89