It looks like you're new here. If you want to get involved, click one of these buttons!
@synthesize mainImage, buttonClicked, radarImagesArray, analyzingImagesArray, arr1;
- (void)viewDidLoad {
int counter = 1;
mainStatus = 0;
[buttonClicked setImage: [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@\"analyze\" ofType:@\"png\"]] forState:UIControlStateNormal];
arr1 = [[NSMutableArray alloc] init];
[arr1 addObject:@\"image1\"];
[arr1 addObject:@\"image2\"];
NSString *temp;
UIImage *tempImage;
temp = [[NSString alloc] init];
tempImage = [[UIImage alloc] init];
radarImagesArray = [[NSMutableArray alloc] init];
analyzingImagesArray = [[NSMutableArray alloc] init];
for(int x = 1; x <= 75; x++){
NSString *holder = [[NSString alloc] init];
if(counter < 10){
holder = [NSString stringWithFormat: @\"00\"];
}
if(counter >= 10 && counter < 100){
holder = [NSString stringWithFormat: @\"0\"];
}
temp = [NSString stringWithFormat:@\"iStock_000003493496Small We %@%i\", holder, x];
tempImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:temp ofType:@\"jpg\"]];
if(tempImage){
[radarImagesArray addObject: tempImage];
//[tempImage release];
//[tempImage dealloc];
}
//if(temp)[temp release];
counter++;
}
counter = 1;
for(int x = 1; x <= 20; x++){
NSString *holder = [[NSString alloc] init];
if(counter < 10){
holder = [NSString stringWithFormat: @\"00\"];
}
if(counter >= 10 && counter < 100){
holder = [NSString stringWithFormat: @\"0\"];
}
temp = [NSString stringWithFormat:@\"iStock_000004494873Small We %@%i\", holder, x];
tempImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:temp ofType:@\"jpg\"]];
if(tempImage){
[analyzingImagesArray addObject: tempImage];
//[tempImage release];
}
//if(temp)[temp release];
counter++;
}
[mainImage setAnimationImages: radarImagesArray];
[mainImage startAnimating];
[super viewDidLoad];
}
#import <UIKit/UIKit.h>
@interface MandarViewController : UIViewController {
IBOutlet UIImageView *mainImage;
IBOutlet UIButton *buttonClicked;
NSMutableArray *radarImagesArray;
NSMutableArray *analyzingImagesArray;
NSMutableArray *arr1;
int mainStatus;
}
@property(nonatomic, retain) UIImageView *mainImage;
@property(nonatomic, retain) NSMutableArray *radarImagesArray;
@property(nonatomic, retain) NSMutableArray *analyzingImagesArray;
@property(nonatomic, retain) NSMutableArray *arr1;
@property(nonatomic, retain) UIButton *buttonClicked;
-(IBAction)buttonClicked:(id)sender;
-(void)stopBuildingAnalyzingImagesArray;
@end
Replies
On a side note, your code (comments added to show issues):
can be changed to:
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAlso make the call to '[super viewDidLoad]' the first line of code, not the last. This general rule should always be followed when overloading a parent method unless you have a specific reason to call it later in the overloaded method.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks for the tips! I'm new to this. I will move the function over to where you said. As far as the memory leak you mentioned, I didn't see how you said to fix it. Did I miss something? Thanks for the tips!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAs for the memory leak, it's no longer there with the suggested code I posted. You have no reason to allocate an NSString object in this case.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI am facing problem with loading more number of images into memory. When I load the images from application bundle using imageNamed API of UIImage and add it to UIImageView, The instruments does not show any spike in memory utilization, whereas when I load the image with imageWithContentsOfFile and add it to UIImageView, there's a whole lot of memory utilization.
Is there any difference with imageNamed and imageWithContentsOfFile,
Can I use imageNamed: to load image located at other that application bundle?
Or
How can I add the image into system cache?
iOS Blog : http://iphone2020.wordpress.com
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIf you need to load an image once or you need to use larger images you are better off using imageWithContentsOfFile. Just make sure you release everything when you are done to give the memory back.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHere are some of my observations which i thought of sharing it.
*Loading an image using imageWithContentsOfFile will not actually load the image into memory. The image is loaded only when it is used for drawing on a view
*Once the image is drawn onto image, we have to explicitly release the image to remove it completely from the memory
* However. Loading an image using imageNamed does not acutally load into memory even it is drawn onto the view( checked the objectAllocation in the instuments and there is trace of this image data). might be it is using the system cache
* imageNamed only loads images from your resources directory
iOS Blog : http://iphone2020.wordpress.com
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeiOS Blog : http://iphone2020.wordpress.com
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI would have a list of the image file path, but only load the image with imageWithContentOfFile when I need it.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome