objective c - iOS: is it possible to create a matrix of NSObjects? -
objective c - iOS: is it possible to create a matrix of NSObjects? -
since objective c superset of c it' possible utilize malloc/free primitive types create matrix of nxm elements. wouldn't because may cause bugs , memory leaks. lastly point still true? arc provide releasing of c types?
int** matrix=(int**)malloc(n*sizeof(int*)); for(int i=0; i<n; i++) matrix[i]=(int*)malloc(m*sizeof(int));
is possible objective-c way? found nsmatrix it's mac, not ios.
do arc provide releasing of c types?
no, not. arc stands automated reference counting, meaning works reference-counted objects.
since malloc
/free
deals "plain" freestore allocations, memory blocks receive malloc
not eligible arc.
this not mean, however, couldn't accomplish grade of automation in managing malloc
-allocated memory "piggybacking" on arc:
dealloc
method calls free
on allocated memory blocks. now have reference-counted class holds matrix. whenever arc instructs class deallocate, memory held matrix gets released well:
@interface matrix : nsobject @property (nonatomic, readonly) int** data; -(instancetype)initiwithrows:(nsuinteger)rows andcolumns:(nsuinteger)cols; -(void)dealloc; @end
ios objective-c c matrix memory-leaks
Comments
Post a Comment