views:

116

answers:

3

My code works fine on my ipod, it's not slow and doesn't crash, but using Instruments I discovered 826 leaked blocks. The Header file is:

#import "CountySelectionViewController.h"
#import "iProspectLiteAnnotation.h"
#import "iProspectLiteAnnotationView.h"
#import <CoreLocation/CoreLocation.h>
#import <iAd/iAd.h>
#import <sqlite3.h>
#import <CoreData/CoreData.h>
@protocol MainViewControllerDelegate;

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, CLLocationManagerDelegate, ADBannerViewDelegate> 
{
 IBOutlet MKMapView *mapView;
 CLLocationManager *locationManager;
 ADBannerView *bannerView;
 NSManagedObjectContext *managedObjectContext;
 NSString *databaseName;
 NSString *databasePath;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, retain) ADBannerView *bannerView;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
-(IBAction)showInfo;
-(IBAction)changeViewRegion;
-(IBAction)showUserLocation;
-(IBAction)zoomUserLocation;
-(void)loadAnnotations;
@end
@protocol MainViewControllerDelegate
- (void)mainViewControllerDidFinish:(MainViewController *)controller;
@end

the implementation file is:

#import "MainViewController.h"
#import "MainViewController.h"
#import "iProspectLiteAppDelegate.h"
#import "FlipsideViewController.h"
#import "CountySelectionViewController.h"
#import "iProspectLiteAnnotation.h"
#import "Mine.h"
@implementation MainViewController
@synthesize locationManager, mapView, bannerView, managedObjectContext;
//nib initialization method omitted
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{ 
}
-(void) checkAndCreateDatabase
{
 NSLog(@"check and create Database");
 BOOL success;
 NSFileManager *fileManager = [NSFileManager defaultManager];
 success = [fileManager fileExistsAtPath:databasePath];
 if(success) return;
 NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
 [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
 [fileManager release];
 NSLog(@"database checked and created");
}
- (void)deleteAllObjects 
{
 NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
 NSEntityDescription *entity = [NSEntityDescription entityForName:@"Mine" inManagedObjectContext:managedObjectContext];
 [fetchRequest setEntity:entity];
 NSError *error;
 NSArray *items = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
 [fetchRequest release];
 NSLog(@"deleting");
 for (NSManagedObject *managedObject in items) 
 {
  [managedObjectContext deleteObject:managedObject];
 }
 if (![managedObjectContext save:&error]) 
 {
 }
}
-(void)readMinesFromDatabase 
{
 sqlite3 *database;
 [self deleteAllObjects];
 if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) 
 {
  const char *sqlStatement = "SELECT * FROM mines";
  sqlite3_stmt *compiledStatement;
  if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) != SQLITE_OK) 
  {
   NSLog( @"Error: Failed to prepare stmt with message %s", sqlite3_errmsg(database));
  }
  else 
  {

   while(sqlite3_step(compiledStatement) == SQLITE_ROW) 
   {
    Mine *mine = (Mine *)[NSEntityDescription insertNewObjectForEntityForName:@"Mine" inManagedObjectContext:managedObjectContext];
    [mine setPrimarykey:[NSNumber numberWithInteger:(int )sqlite3_column_double(compiledStatement, 0)]];
    [mine setLatitude:[NSNumber numberWithDouble:(double )sqlite3_column_double(compiledStatement, 2)]];
    [mine setLongitude:[NSNumber numberWithDouble:(double )sqlite3_column_double(compiledStatement, 3)]];
    [mine setName:[NSString  stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]];
    [mine setCounty:[NSString  stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)]];
    [mine setFirstCommodity:[NSString  stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)]];
    [mine setSecondCommodity:[NSString  stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)]];
    [mine setThirdCommodity:[NSString  stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 7)]]; 
   }
   NSError *error;
   if (![managedObjectContext save:&error]) 
   {
   }
  }
  sqlite3_finalize(compiledStatement);
 }
 sqlite3_close(database);
 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 [defaults setBool:YES forKey:@"database"];
 [defaults synchronize];
} 
-(void)loadAnnotations
{

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Mine" inManagedObjectContext:managedObjectContext];   
NSFetchRequest *request = [[NSFetchRequest alloc] init];   
NSError *error = nil;
[request setEntity:entity];  
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *region = [defaults stringForKey:@"mineArray"];
NSPredicate* metalFilter=[NSPredicate predicateWithFormat:@"(firstCommodity Contains %@)",@"unobtainium"];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"(county Contains %@)",region];
[request setPredicate:predicate];
NSMutableArray *minesArray = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
[request release];
NSLog(@"county filter %i", [minesArray count]);
if([defaults integerForKey:@"metalControl"] == 2)
{
    metalFilter = [NSPredicate predicateWithFormat:@"(firstCommodity Contains%@ OR firstCommodity Contains%@)", @"Gold" , @"None"];
}
else if([defaults integerForKey:@"metalControl"] == 3)
{
    metalFilter = [NSPredicate predicateWithFormat:@"(firstCommodity Contains%@ OR firstCommodity Contains%@)", @"Silver", @"None"];
}
else if([defaults integerForKey:@"metalControl"] == 0)
{
    metalFilter = [NSPredicate predicateWithFormat:@"(firstCommodity Contains%@ OR firstCommodity Contains%@)", @"Copper", @"None"];
}
[minesArray filterUsingPredicate:metalFilter];
NSLog(@"metal 1 and empty filter %i", [minesArray count]);
NSRange goldMatch;
NSRange silverMatch;
NSRange copperMatch;
NSLog(@"starting Loop");
[mapView removeAnnotations:mapView.annotations];
CLLocationCoordinate2D workingCoordinate;
if([minesArray count] != 0)
{
    for(Mine* mine in minesArray)
    {

        workingCoordinate.latitude = [[mine latitude] doubleValue];
        workingCoordinate.longitude = [[mine longitude] doubleValue];

        iProspectLiteAnnotation *tempMine = [[iProspectLiteAnnotation alloc] initWithCoordinate:workingCoordinate];
        [tempMine setTitle:[mine name]];


    if([[mine firstCommodity] isEqualToString:@"None"])
        {
            if([[mine secondCommodity] isEqualToString:@"None"])
            {
                goldMatch = [[mine thirdCommodity] rangeOfString:@"Gold"];
                silverMatch = [[mine thirdCommodity] rangeOfString:@"Silver"];
                copperMatch = [[mine thirdCommodity] rangeOfString:@"Copper"];
                if(goldMatch.location != NSNotFound && [defaults integerForKey:@"metalControl"] == 2)
                {
                    [tempMine setAnnotationType:iProspectLiteAnnotationTypeGold];
                    [mapView addAnnotation:tempMine];
                }
                else if(silverMatch.location != NSNotFound && [defaults integerForKey:@"metalControl"] == 3)
                {
                    [tempMine setAnnotationType:iProspectLiteAnnotationTypeSilver];
                    [mapView addAnnotation:tempMine];
                }
                else if(copperMatch.location != NSNotFound && [defaults integerForKey:@"metalControl"] == 0)
                {
                    [tempMine setAnnotationType:iProspectLiteAnnotationTypeCopper];
                    [mapView addAnnotation:tempMine];
                }
            }
            else 
            {
                goldMatch = [[mine secondCommodity] rangeOfString:@"Gold"];
                silverMatch = [[mine secondCommodity] rangeOfString:@"Silver"];
                copperMatch = [[mine secondCommodity] rangeOfString:@"Copper"];
                if(goldMatch.location != NSNotFound && [defaults integerForKey:@"metalControl"] == 2)
                {
                    [tempMine setAnnotationType:iProspectLiteAnnotationTypeGold];
                    [mapView addAnnotation:tempMine];
                }
                else if(silverMatch.location != NSNotFound && [defaults integerForKey:@"metalControl"] == 3)
                {
                    [tempMine setAnnotationType:iProspectLiteAnnotationTypeSilver];
                    [mapView addAnnotation:tempMine];
                }
                else if(copperMatch.location != NSNotFound && [defaults integerForKey:@"metalControl"] == 0)
                {
                    [tempMine setAnnotationType:iProspectLiteAnnotationTypeCopper];
                    [mapView addAnnotation:tempMine];
                }
            }

    }
    else
    {

        if ([defaults integerForKey:@"metalControl"] == 2)
        {

            [tempMine setAnnotationType:iProspectLiteAnnotationTypeGold];
            [mapView addAnnotation:tempMine];

        }
        else if([defaults integerForKey:@"metalControl"] == 3)
        {

            [tempMine setAnnotationType:iProspectLiteAnnotationTypeSilver];
            [mapView addAnnotation:tempMine];
        }
        else if([defaults integerForKey:@"metalControl"] == 0)
        {

            [tempMine setAnnotationType:iProspectLiteAnnotationTypeCopper];
            [mapView addAnnotation:tempMine];
        }
    }

    [tempMine release];

    }
}
[minesArray release];
 }

-(IBAction)showUserLocation
{
 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 if([defaults integerForKey:@"location"] == 1)
 {
  CLLocation *location = [locationManager location];
  CLLocationCoordinate2D workingCoordinate = [location coordinate];
  iProspectLiteAnnotation *tempMine = [[iProspectLiteAnnotation alloc] initWithCoordinate:workingCoordinate];
  [tempMine setTitle:@"Present Location"];
  [tempMine setAnnotationType:iProspectLiteAnnotationTypeUser];
  [mapView addAnnotation:tempMine];
  [mapView setCenterCoordinate:workingCoordinate animated:YES];
  [tempMine release];
 }
}

- (void)showBanner {

    CGFloat fullViewHeight = self.view.frame.size.height;
    CGRect bannerFrame = self.bannerView.frame;


    bannerFrame.origin.y = fullViewHeight - bannerFrame.size.height; 

    [UIView beginAnimations:@"showBanner" context:NULL];
    self.bannerView.frame = bannerFrame;
    [UIView commitAnimations];
}

- (void)hideBanner {
    CGFloat fullViewHeight = self.view.frame.size.height;
    CGRect bannerFrame = self.bannerView.frame;
    bannerFrame.origin.y = fullViewHeight;
    self.bannerView.frame = bannerFrame;
}

- (void)createBannerView {
    Class cls = NSClassFromString(@"ADBannerView");
    if (cls != nil) {
        ADBannerView *adView = [[cls alloc] initWithFrame:CGRectZero];
        adView.requiredContentSizeIdentifiers = [NSSet setWithObjects:
             ADBannerContentSizeIdentifier320x50,
             ADBannerContentSizeIdentifier480x32,
             nil];
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
  adView.delegate = self;
  adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |
  UIViewAutoresizingFlexibleRightMargin;
        CGRect bannerFrame =adView.frame;
        bannerFrame.origin.y = self.view.frame.size.height;
        adView.frame = bannerFrame;
        self.bannerView = adView;
        [self.view addSubview:adView];
        [adView release];
    }
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    [self showBanner];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    [self hideBanner];
}



-(IBAction)zoomUserLocation
{ 
 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 if([defaults integerForKey:@"location"] == 1)
 {
  CLLocation *location = [locationManager location];
  CLLocationCoordinate2D workingCoordinate = [location coordinate];
  [mapView setCenterCoordinate:workingCoordinate animated:YES];
  MKCoordinateRegion initialRegion = [mapView region];
  double iLa = initialRegion.span.latitudeDelta;
  double iLo = initialRegion.span.longitudeDelta;
  MKCoordinateRegion finalRegion;
  finalRegion.center = workingCoordinate;
  MKCoordinateSpan span;
  span.latitudeDelta=iLa - (.9 * iLa);
  span.longitudeDelta=iLo - (.9 * iLo);
  finalRegion.span=span;
  [mapView setRegion:finalRegion animated:YES];
 }
}


- (CLLocationManager *)locationManager {
    if (locationManager != nil) {
        return locationManager;
    }
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
    [locationManager setDelegate:self];
    return locationManager;
}

- (iProspectLiteAnnotationView *)mapView:(MKMapView *)mapV viewForAnnotation:(id <MKAnnotation>)annotation
 {

iProspectLiteAnnotationView *annotationView = nil;

iProspectLiteAnnotation* myAnnotation = (iProspectLiteAnnotation *)annotation;
NSString* identifier;
if(myAnnotation.annotationType == iProspectLiteAnnotationTypeGold)
{
    identifier = @"Gold";
}
else if(myAnnotation.annotationType == iProspectLiteAnnotationTypeSilver)
{
    identifier = @"Silver";
}
else if(myAnnotation.annotationType == iProspectLiteAnnotationTypeCopper)
{
    identifier = @"Copper";
}
else if(myAnnotation.annotationType == iProspectLiteAnnotationTypeUser)
{
    identifier = @"Present Location";
}
iProspectLiteAnnotationView *newAnnotationView = (iProspectLiteAnnotationView *)[mapV dequeueReusableAnnotationViewWithIdentifier:identifier];
if(nil == newAnnotationView)
{
    newAnnotationView = [[[iProspectLiteAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
}

annotationView = newAnnotationView;
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:YES];
return annotationView;
}

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller 
{  
 [self dismissModalViewControllerAnimated:YES];
 NSLog(@"back to mainViewController");
 [self loadAnnotations];
}


- (IBAction)showInfo {    
 NSLog(@"to FlipsideViewController");
 FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
 controller.delegate = self;
 controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
 [self presentModalViewController:controller animated:YES];
 [controller release];
}

-(IBAction)changeViewRegion {
 [self dismissModalViewControllerAnimated:YES];
 NSLog(@"After view controller");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
 if (self.bannerView)
 {
  bannerView.delegate = nil;
  self.bannerView = nil;
  [bannerView release];
  bannerView= nil;
 } 
}

- (void)dealloc {
 if (bannerView) {
        bannerView.delegate = nil;
        [bannerView release];
    }
 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 if([defaults integerForKey:@"location"] == 1)
 {
  [locationManager release];
 }
 [super dealloc];
}

- (void)viewDidLoad {
 NSLog(@"before super ViewDidLoad");
 [super viewDidLoad];
 NSLog(@"After super ViewDidLoad");
 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 if (managedObjectContext == nil) 
 { 
        managedObjectContext = [(iProspectLiteAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
 }
 if([defaults boolForKey:@"database"] == 0)
 {
  databaseName = @"ml30.sql";
  NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDir = [documentPaths objectAtIndex:0];
  databasePath = [documentsDir stringByAppendingPathComponent:databaseName]; 
  [self checkAndCreateDatabase];
  [self readMinesFromDatabase];
 }
 CLLocationCoordinate2D workingCoordinate;
 MKCoordinateRegion finalRegion;
 MKCoordinateSpan span;
 [defaults setInteger:1 forKey:@"metalControl"];
 if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Butte"])
 {
  workingCoordinate.latitude = 39.69788;
  workingCoordinate.longitude = -121.473706;
  span.latitudeDelta= .6;
  span.longitudeDelta= .6;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 }
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Plumas"])
 {
  workingCoordinate.latitude = 40.0;
  workingCoordinate.longitude = -120.946362;
  span.latitudeDelta= .6;
  span.longitudeDelta= .6;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 }
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Sierra"])
 {
  workingCoordinate.latitude = 39.55867;
  workingCoordinate.longitude = -120.801506;
  span.latitudeDelta= .5;
  span.longitudeDelta= .5;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 }
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Yuba"])
 {
  workingCoordinate.latitude = 39.353382;
  workingCoordinate.longitude = -121.1648;
  span.latitudeDelta= 1;
  span.longitudeDelta= 1;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 }
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Nevada"])
 {
  workingCoordinate.latitude = 39.303382;
  workingCoordinate.longitude = -120.8048;
  span.latitudeDelta= .55;
  span.longitudeDelta= .55;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 }
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Placer"])
 {
  workingCoordinate.latitude = 39.103382;
  workingCoordinate.longitude = -120.7648;
  span.latitudeDelta= .67;
  span.longitudeDelta= .67;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 }
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"El Dorado"])
 {
  workingCoordinate.latitude = 38.753382;
  workingCoordinate.longitude = -120.5648;
  span.latitudeDelta= .6;
  span.longitudeDelta= .6;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 } 
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Sacramento"])
 {
  workingCoordinate.latitude = 38.553382;
  workingCoordinate.longitude = -121.2048;
  span.latitudeDelta= .4;
  span.longitudeDelta= .4;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 } 
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Amador"])
 {
  workingCoordinate.latitude = 38.43382;
  workingCoordinate.longitude = -120.7648;
  span.latitudeDelta= .53;
  span.longitudeDelta= .53;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 } 
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"San Joaquin"])
 {
  workingCoordinate.latitude = 37.953382;
  workingCoordinate.longitude = -120.9648;
  span.latitudeDelta= .54;
  span.longitudeDelta= .54;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 } 
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Calaveras"])
 {
  workingCoordinate.latitude = 38.133382;
  workingCoordinate.longitude = -120.6748;
  span.latitudeDelta= .8;
  span.longitudeDelta= .8;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 } 
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Stanislaus"])
 {
  workingCoordinate.latitude = 37.853382;
  workingCoordinate.longitude = -120.6548;
  span.latitudeDelta= .5;
  span.longitudeDelta= .5;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 } 
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Tuolumne"])
 {
  workingCoordinate.latitude = 37.933382;
  workingCoordinate.longitude = -120.2448;
  span.latitudeDelta= .8;
  span.longitudeDelta= .8;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 } 
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Mariposa"])
 {
  workingCoordinate.latitude = 37.553382;
  workingCoordinate.longitude = -120.0648;
  span.latitudeDelta= .8;
  span.longitudeDelta= .8;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 }
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Merced"])
 {
  workingCoordinate.latitude = 37.453382;
  workingCoordinate.longitude = -120.3648;
  span.latitudeDelta= .4;
  span.longitudeDelta= .4;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 }
 else if([[defaults stringForKey:@"mineArray"] isEqualToString:@"Madera"])
 {
  workingCoordinate.latitude = 37.293382;
  workingCoordinate.longitude = -119.6648;
  span.latitudeDelta= .8;
  span.longitudeDelta= .8;
  finalRegion.center = workingCoordinate;
  finalRegion.span = span;
  [mapView setRegion:finalRegion animated:NO];
 }
  if([defaults integerForKey:@"location"] != 2 && [defaults integerForKey:@"location"] != 1 )
  {
   [defaults setInteger:2 forKey:@"location"];
   [defaults synchronize];
   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"iProspect Lite would like to use your current location. Denying will inhibit certain features."delegate:self cancelButtonTitle:nil otherButtonTitles:@"Deny", @"Allow",nil];
   [alert show];
   [alert release];
    }
 else 
 {
  if (locationManager == nil && [defaults integerForKey:@"location"] == 1)
  {
   locationManager = [[CLLocationManager alloc] init];
   locationManager.delegate = self;
   locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
   locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; // 10 m
   [locationManager startUpdatingLocation];
   NSLog(@"created and initialized locationManager");
  }
 }
 [self loadAnnotations];
 [self createBannerView];
}

- (void)alertView: (UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 if (buttonIndex==0) 
 {
 }
 else if (buttonIndex==1)
 {
  [defaults setInteger:1 forKey:@"location"];
  locationManager = [[CLLocationManager alloc] init];
  locationManager.delegate = self;
  locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
  locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; // 10 m
  [locationManager startUpdatingLocation];
  NSLog(@"created and initialized locationManager");
 }
 [defaults synchronize];
}
@end

Instruments has this to say about the leaked blocks:

leaked object|#|size|responsible library|responsible frame

  1. NSCFString|800|23.38KB|CoreData|-[NSSQLCore _prepareResultsFromResultset:usingFetchPlan:withMatchingRows:]

  2. NSCFString|15|512 Bytes|CoreData|" "

  3. NSArrayM|5|160Bytes|iProspectLite|-[MainViewController loadAnnotations]

  4. NSAutorelease|4|128 Bytes|Foundation|+[NSAutoreleasePool

  5. NSArrayM|2|64 Bytes|iProspectLite|[MainViewController loadAnnotations]

A: 

Because of the max character length of the question, Here is the rest of the info:

additional header file import statements:

#import "FlipsideViewController.h"
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

IBAction Header file statement:

-(IBAction)metalValueDidChange:(id)sender;

Additional Implementation File Methods:

 -(IBAction)metalValueDidChange: (id) sender {
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     if([defaults integerForKey:@"metalControl"] == 0 ) 
     {
      [sender setTitle:@"Show Gold Mines" forState:UIControlStateNormal];
      [sender setTitleColor:[UIColor yellowColor ]forState:UIControlStateNormal];
      [defaults setInteger:1 forKey:@"metalControl"];
      [self loadAnnotations];
     }
     else if([defaults integerForKey:@"metalControl"] == 1)
     {
      [sender setTitle:@"Show Silver Mines" forState:UIControlStateNormal];
      [sender setTitleColor:[UIColor lightGrayColor]forState:UIControlStateNormal];
      [defaults setInteger:2 forKey:@"metalControl"];
      [self loadAnnotations];
     }
     else if([defaults integerForKey:@"metalControl"] == 2)
     {
      [sender setTitle:@"Show Copper Mines" forState:UIControlStateNormal];
      [sender setTitleColor:[UIColor orangeColor ]forState:UIControlStateNormal];
      [defaults setInteger:3 forKey:@"metalControl"];
      [self loadAnnotations];
     }
     else if([defaults integerForKey:@"metalControl"] == 3)
     {
      [sender setTitle:@"Show No Mines" forState:UIControlStateNormal];
      [sender setTitleColor:[UIColor blackColor ]forState:UIControlStateNormal];
      [defaults setInteger:0 forKey:@"metalControl"];
      [mapView removeAnnotations:mapView.annotations];
      [self loadAnnotations];
     }
     [defaults synchronize];
    }



   - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your location could not be determined. iProspect Lite Cannot update your current location." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
kevin Mendoza
Spilling over like this is a hint that you're posting too much code with too little thought. You'll get a better response if you make some effort to narrow down the source of the problem before posting.
walkytalky
Which Is what I have been trying to do. Idk, I feel like I should take this down now because of all the down votes, but I really have no other option : /.
kevin Mendoza
A: 

you should start releasing every object you are allocating after using it

JonLOo
Even the ones he needs later on ? Seriously, not a good answer.
DarkDust
no, maybe i went to fast, when i said after using it, i wanted to say when you finish using it..
JonLOo
I know that concept, and Thought I could apply it properly using release on every initialized object after I was done using it, but apparently I didn't do it properly, and I can't figure out why.
kevin Mendoza
+4  A: 

have you analyzed your project with the static analyzer in xcode? If not, please do so, Build and Analyze in the Build-menu
The leak I found after a very quick look should be discoverable by the analyzer too.

-(void)loadAnnotations
....
NSMutableArray *minesArray=[[NSMutableArray alloc] init];
....
minesArray = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
fluchtpunkt
+1 You figured out the error in the code mess.
Kinderchocolate
Ok Changing those two lines to NSMutableArray *minesArray = [[managedObjectContext executeFetchRequest:request error: did eliminate a few leaks. I don't understand why though.
kevin Mendoza
@kevin: because the first line allocated an array (that's what `alloc` means) that was never used or released before you lost the reference to it by replacing it with the copy of the fetch request. Remember the basic rules of memory management: balance every `alloc`, `copy`, `new`, or `retain` with a `release` or `autorelease`.
zem
If you still don't understand, I strongly recommend you grab an Objective-C book.
Kinderchocolate
Well no I get that now. I just had never heard of copy or new being the equivalent of an initialize statement.
kevin Mendoza
@kevin: No, that's not the point. The point is you created a new object with retain count 1 (`[[NSMutableArray alloc] init]`) and then you overwrote the pointer to it without releasing it.
DarkDust
So then I'm interpreting overwriting in objective C wrongly then. Ok, fair enough. So I thought it was - initialize -assign -release, but I guess I didn't assign it properly?
kevin Mendoza