Hello i have an array of uiimage views in a function.
But the problem is when i call the function is sometimes i would like
to change the images, so how could i do it and releasing the memory
to avoid memory leaks.
FicherosBolasGrises is a NSMutable array of strings where i save the names
Of the images files.
In another function if i need i change the images in FicheroBolasGrises,
The problem is when i call the function to assing the images to the array
Of image views because i have not releases before, how i could release the array of image views to avoid memory leaks?
Any help?
Thanks a lot
Quote:
Originally Posted by juanchofern
Hello i have an array of uiimage views in a function.
But the problem is when i call the function is sometimes i would like
to change the images, so how could i do it and releasing the memory
to avoid memory leaks.
Hello i have an array of uiimage views in a function.
But the problem is when i call the function is sometimes i would like
to change the images, so how could i do it and releasing the memory
to avoid memory leaks.
NSArrays and mutable arrays retain the objects that they contain. By adding anImageView to the NSMutableArray, the array becomes the owner.
The code above creates the image view using an alloc call, which returns an object you own and must release.
We pass ownership of the image view to the array, and then release the object.
After that code, only the array owns the image view. That's what you want. Then, if you later remove the object from the array, the array will release it and it will be deallocated.
If you release the array, all of the objects in the array will be released and deallocated.
Note that you usually add image views as subviews in your view hierarchy. Adding a view as a subview of another view also retains that view.
If you add an image view to an array AND add it as a subview of your view controller, it will be retained twice. To release it and free it up, you would need to both remove it from the array and remove it from it's parent view (or superview, as Cocoa touch calls it.) That's ok, but you need to make sure your code removes it from it's superview.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
NSArrays and mutable arrays retain the objects that they contain. By adding anImageView to the NSMutableArray, the array becomes the owner.
The code above creates the image view using an alloc call, which returns an object you own and must release.
We pass ownership of the image view to the array, and then release the object.
After that code, only the array owns the image view. That's what you want. Then, if you later remove the object from the array, the array will release it and it will be deallocated.
If you release the array, all of the objects in the array will be released and deallocated.
Note that you usually add image views as subviews in your view hierarchy. Adding a view as a subview of another view also retains that view.
If you add an image view to an array AND add it as a subview of your view controller, it will be retained twice. To release it and free it up, you would need to both remove it from the array and remove it from it's parent view (or superview, as Cocoa touch calls it.) That's ok, but you need to make sure your code removes it from it's superview.
Hello Duncan again,
i have created a NSMutableArray as you said me.
But now how can i acces to the properties of an UIImageView.
Before i did tBolasGrises[i].hidden=Yes.
But now i cannot do [tBolasGrises ObjectAtIndex:i].hidden=Yes
i suppose because is a array of objects.
How can i do it?
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.