Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-25-2010, 06:55 PM   #1 (permalink)
Car Enthusiast/Indie Dev
 
taylor202's Avatar
 
Join Date: Nov 2009
Location: For Worth, Texas
Age: 23
Posts: 229
taylor202 is on a distinguished road
Default Memory Warning In Chat Room App

Hey guys, I apparently have a Autoreleasepool leak and i cannot find it for the life of me. I have used all of the instrument tools. Here is my code if anyone can help.

Code:
@implementation ChatCloudViewController
@synthesize map,zoomInButton,zoomOutButton,messageField,messageTableController,communicator,followToggle,settingsViewController,filterButton,settingsButton;

-(void)userGoingBackToPublicView{
	NSLog(@"Dismissing privateMessageView to show the public view");
	[self dismissModalViewControllerAnimated:YES];
}
-(void)messageSelected:(Message *)message{
	NSLog(@"Message: %@ was selected",message.text);
	PrivateMessageViewController* timer = [[PrivateMessageViewController alloc] initWithNibName:nil bundle:nil];
	timer.delegate = self;
	timer.theBio=message.bio;
	timer.theName=message.name;
	timer.theMsg=message.text;
	timer.theLocation=message.location;
	[self presentModalViewController:timer animated:YES];
}
-(IBAction)goBack
{
	
	//NSLog(@"retainCount:%d", [communicator retainCount]);
	//[communicator release];
	
	//NSLog(@"retainCount:%d", [communicator retainCount]);
	[self.communicator stopTimer];
	
	
	
	[self dismissModalViewControllerAnimated:YES];
	
}
-(IBAction)zoomMapIn:(UIButton*)sender{
	zoomLevel+=1;
	
	if(zoomLevel==1){
		zoomOutButton.hidden = NO;
	}
	
	if(zoomLevel>=19){
		zoomLevel = 19;
		zoomInButton.hidden = YES;
	}
	//NSLog([NSString stringWithFormat:@"zoomLevel:%d",zoomLevel]);
	[self performZoom];
}
-(IBAction)zoomMapOut:(UIButton*)sender{
	zoomLevel-=1;
	
	if(zoomLevel==18){
		zoomInButton.hidden = NO;
	}
	if(zoomLevel<=0){
		zoomLevel = 0;
		zoomOutButton.hidden = YES;
	}
	//NSLog([NSString stringWithFormat:@"zoomLevel:%d",zoomLevel]);
	[self performZoom];
}

-(void)performZoom{
	if(following){
		[map setCenterCoordinate:map.userLocation.coordinate zoomLevel:zoomLevel animated:YES];
	}
	else{
		[map setCenterCoordinate:map.centerCoordinate zoomLevel:zoomLevel animated:YES];
	}
}

-(IBAction)showSettings{
	NSLog(@"Pushing the settings view in response to user click settings");
	[self presentModalViewController:settingsViewController animated:YES];
	[settingsViewController release];
}

-(IBAction)performFilter:(UIButton*)sender{
	float minLatitude = map.region.center.latitude - (map.region.span.latitudeDelta/2);
	float maxLatitude = map.region.center.latitude + (map.region.span.latitudeDelta/2);
	float minLongitude = map.region.center.longitude - (map.region.span.longitudeDelta/2);
	float maxLongitude = map.region.center.longitude + (map.region.span.longitudeDelta/2);
	NSLog(@"minlat:%f\nmaxlat:%f\nminlong:%f\nmaxlong:%f\n",minLatitude,maxLatitude,minLongitude,maxLongitude);
	
	
	[messageTableController filterMessagesByMinLatitude:minLatitude 
											maxLatitude:maxLatitude 
										andMinLongitude:minLongitude 
										   maxLongitude:maxLongitude];
}

-(NSMutableArray *)latitudeCalculator{
	NSNumber *minLatitude = [NSNumber numberWithFloat:map.region.center.latitude - (map.region.span.latitudeDelta/2)];
	NSNumber *maxLatitude = [NSNumber numberWithFloat:map.region.center.latitude + (map.region.span.latitudeDelta/2)];
	NSNumber *minLongitude = [NSNumber numberWithFloat:map.region.center.longitude - (map.region.span.longitudeDelta/2)];
	NSNumber *maxLongitude = [NSNumber numberWithFloat:map.region.center.longitude + (map.region.span.longitudeDelta/2)];
	
	
	NSMutableArray *coordinates = [NSMutableArray array];
	[coordinates addObject:minLatitude];
	[coordinates addObject:maxLatitude];
	[coordinates addObject:minLongitude];
	[coordinates addObject:maxLongitude];
	return coordinates;
	
}

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView {
 }
 */



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	NSString *msg = [[NSString alloc] initWithFormat:@"ALLOW THE BLUE DOT TO ZERO INTO YOUR POSITION. If you notice the chat room lagging or multiple posting, just press go back and reopen the room. This fixes the majority of the problems. If that doesnt fix it please contact us."];
	
	UIAlertView *alert = [[UIAlertView alloc]
						  initWithTitle: @"Gamer Lounge"
						  message: msg
						  delegate: nil
						  cancelButtonTitle: @"OK"
						  otherButtonTitles: nil];
	
	[alert show];
	[alert release];
	[msg release];
    [super viewDidLoad];
	locationController = [[ChatCloudLocationController alloc] init];
	locationController.delegate = self;
    [locationController.locationManager startUpdatingLocation];
	map.mapType = MKMapTypeHybrid;
	map.zoomEnabled=TRUE;
	
	UITapGestureRecognizer* rec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchChangedWithGestureRecognizer)];
	rec.numberOfTouchesRequired=2;
	// set options for this recognizer.
	[map addGestureRecognizer:rec];
	[rec release];
	
	following = NO;
	mapOnlyView = NO;
	
	audioController = [[ChatCloudAudioController alloc] init];
	//[audioController release];
	
	//NSLog(@"retainCount:%d", [communicator retainCount]);
	//ChatCloudCommunicationController *comm =[[ChatCloudCommunicationController alloc] init];
	
	
	[communicator startTimer];
	
	

}

-(void)touchChangedWithGestureRecognizer{
	NSLog(@"User tapped the map view");
	[messageField resignFirstResponder];
	
	
	if([self interfaceOrientation]==UIInterfaceOrientationLandscapeLeft||[self interfaceOrientation]==UIInterfaceOrientationLandscapeRight){
		[UIView beginAnimations:nil context:nil];
		[UIView setAnimationDuration:1.2];
		// Defaults to ease in and ease out [UIView setAnimationCurve
		// also setAnimationDelay
		// call a function when it is done
		int direction;
		if(mapOnlyView){
			direction=-1;
		}
		else{
			direction=1;
		}
		
		messageField.frame = CGRectOffset(messageField.frame,0,direction*150);
		messageTableController.view.frame=CGRectOffset(messageTableController.view.frame, 0, direction*110);
		zoomInButton.frame = CGRectOffset(zoomInButton.frame,0,direction*-62);
		zoomOutButton.frame = CGRectOffset(zoomOutButton.frame,0,direction*-62);
		settingsButton.frame = CGRectOffset(settingsButton.frame,0,direction*-62);
		if(!mapOnlyView){
			map.frame=CGRectMake(0, -20, 480, 320);
		}
		else{
			map.frame=CGRectMake(0, -20, 480, 180);
		}
		
		
		
		[UIView commitAnimations];
		mapOnlyView = !mapOnlyView;
	}
	
	
	
}

- (void)messageUpdateComplete:(NSMutableArray *)newMessages{
	NSLog(@"Communication Controller has sent a message update complete message");
	
	
	for(int i=0;i<[newMessages count];i++){
		
		[messageTableController addMessageToTable:[newMessages objectAtIndex:i]];
		
		CLLocationCoordinate2D placemarkLocation;
		Message *temp = [newMessages objectAtIndex:i];
		placemarkLocation.latitude = temp.latitude;
		placemarkLocation.longitude = temp.longitude;
		placemark=[[PlaceMark alloc] initWithCoordinate:placemarkLocation title:temp.location subtitle:temp.text];
		[map addAnnotation:placemark];
		[placemark release];
		//NEW
		//[temp release];
		
		
	}
	
}
cont...
taylor202 is offline   Reply With Quote
Old 10-25-2010, 06:56 PM   #2 (permalink)
Car Enthusiast/Indie Dev
 
taylor202's Avatar
 
Join Date: Nov 2009
Location: For Worth, Texas
Age: 23
Posts: 229
taylor202 is on a distinguished road
Default

Code:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
	
	NSLog(@"The send button was pressed");
	NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
	name = [standardUserDefaults objectForKey:@"key"];
	if (name== nil || name ==NULL)
		name =@"Anonymous";
	bio = [standardUserDefaults objectForKey:@"bio"];
	if (bio== nil || bio ==NULL)
		bio =@"User dosn't have a bio";
	deviceUUID = [standardUserDefaults objectForKey:@"deviceUUID"];
	if (theTextField == messageField) {
        [messageField resignFirstResponder];
		
		[communicator sendMessageToServerWithLocation:locationController.geocodeLoc 
											 withText:[messageField text] 
										 withLatitude:[NSString stringWithFormat:@"%f",map.userLocation.location.coordinate.latitude] 
										withLongitude:[NSString stringWithFormat:@"%f",map.userLocation.location.coordinate.longitude]
											 withName:[NSString stringWithFormat:name]
							withBio:[NSString stringWithFormat:bio]
				withDeviceUUID:[NSString stringWithFormat:deviceUUID]];
		NSLog(deviceUUID);
		messageField.text=@"";
		
		    }
    return YES;
}


- (void)locationUpdate:(CLLocation *)location {
    map.userLocation.coordinate = location.coordinate;
	map.showsUserLocation=YES;
	if(following){
		[map setCenterCoordinate:map.userLocation.coordinate zoomLevel:zoomLevel animated:YES];
	}
	
}

-(IBAction)toggleFollowing{
	if(!following){
		[map setCenterCoordinate:map.userLocation.coordinate zoomLevel:zoomLevel animated:YES];
	}
	following = !following;
	followToggle.selected = following;
}

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
	
	[[NSRunLoop currentRunLoop] cancelPerformSelector:@selector(filterMessages) target:self argument:nil];
	[self performSelector:@selector(filterMessages) withObject:nil afterDelay:0.25];
}

-(void)filterMessages{
	NSMutableArray* coordinates = [self latitudeCalculator];
	[self.messageTableController filterMessagesByMinLatitude:[[coordinates objectAtIndex:0] floatValue]
												 maxLatitude:[[coordinates objectAtIndex:1] floatValue] 
											 andMinLongitude:[[coordinates objectAtIndex:2] floatValue] 
												maxLongitude:[[coordinates objectAtIndex:3] floatValue]];
}

- (void)locationError:(NSError *)error {
    NSLog(@"%@",[error description]);
}



// Override to allow orientations other than the default portrait orientation.
//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
  //  return (YES);
//}

/*-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
 if(toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft||toInterfaceOrientation==UIInterfaceOrientationLandscapeRight){
 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:duration];
 // Defaults to ease in and ease out [UIView setAnimationCurve
 // also setAnimationDelay
 // call a function when it is done
 map.frame=CGRectMake(0, -20, 480, 180);
 messageField.frame = CGRectMake(10,170,460,31);
 messageTableController.view.frame=CGRectMake(0, 210, 480, 100);
 settingsButton.frame = CGRectOffset(settingsButton.frame, 85, 0);
 zoomOutButton.frame = CGRectOffset(zoomOutButton.frame, 160, 0);
 filterButton.alpha=0;
 followToggle.alpha=0;
 dropShadow.hidden=YES;
 
 [UIView commitAnimations];
 }
 else{
 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:duration];
 map.frame=CGRectMake(0, -20, 320, 180);
 messageField.frame = CGRectMake(10,205,300,31);
 messageTableController.view.frame=CGRectMake(0, 245, 320, 350);
 settingsButton.frame = CGRectMake(123, 0, 73, 43);
 zoomOutButton.frame = CGRectMake(262,0,58,43);
 zoomInButton.frame = CGRectMake(0,0,58,42);
 filterButton.alpha=100;
 followToggle.alpha=100;
 dropShadow.hidden=NO;
 
 
 [UIView commitAnimations];
 
 }
 }
 */
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
    const int movementDistance = 72; // tweak as needed
    const float movementDuration = 0.3f; // tweak as needed
	
    int movement = (up ? -movementDistance : movementDistance);
	
    [UIView beginAnimations: @"anim" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    messageField.frame = CGRectOffset(messageField.frame, 0, movement);
    [UIView commitAnimations];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if([self interfaceOrientation]==UIInterfaceOrientationLandscapeLeft||[self interfaceOrientation]==UIInterfaceOrientationLandscapeRight){
		[self animateTextField: textField up: YES];
	}
}


- (void)textFieldDidEndEditing:(UITextField *)textField
{
	if([self interfaceOrientation]==UIInterfaceOrientationLandscapeLeft||[self interfaceOrientation]==UIInterfaceOrientationLandscapeRight){
		[self animateTextField: textField up: NO];
	}
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}



- (void)viewDidUnload
{
	[map release];
	[zoomInButton release];
	[zoomOutButton release];
	[settingsButton release];
	[filterButton release];
	[messageField release];
	[messageTableController release];
	[communicator release];
	[followToggle release];
	[settingsViewController release];
	[locationController release];
	[audioController release];
	[PrivateMessageViewController release];
	[ChatCloudViewController release];
	
}



- (void)dealloc {
	[map release];
	[zoomInButton release];
	[zoomOutButton release];
	[settingsButton release];
	[filterButton release];
	[messageField release];
	[messageTableController release];
	[communicator release];
	[followToggle release];
	[settingsViewController release];
	[locationController release];
	[audioController release];
	[PrivateMessageViewController release];
	[ChatCloudViewController release];
	
	
    [super dealloc];
}

@end
[/code]
taylor202 is offline   Reply With Quote
Old 10-25-2010, 06:56 PM   #3 (permalink)
Car Enthusiast/Indie Dev
 
taylor202's Avatar
 
Join Date: Nov 2009
Location: For Worth, Texas
Age: 23
Posts: 229
taylor202 is on a distinguished road
Default

COMMUNICATOR CLASS

Code:
@implementation ChatCloudCommunicationController
@synthesize delegate, updating;

-(void)viewDidLoad
{
	num=0;
	
}
-(void)updateMessagesWithMinLatitude:(NSNumber *)minLat 
					  andMaxLatitude:(NSNumber *)maxLat 
					 andMinLongitude:(NSNumber *)minLong 
					 andMaxLongitude:(NSNumber *)maxLong{
	if(!updating)
		
	{
		
		NSLog(@"Performing message table update");
		NSURL *url = [NSURL URLWithString:@"http://www.virtualcoachdesign.com/medalupdate.php"];
		ASIFormDataRequest *messageRequest = [ASIFormDataRequest requestWithURL:url];
		[messageRequest setPostValue:[NSString stringWithFormat:@"%d",currentID]  forKey:@"currentID"];
		[messageRequest setPostValue:[NSString stringWithFormat:@"%f",[minLat floatValue]] forKey:@"minlat"];
		[messageRequest setPostValue:[NSString stringWithFormat:@"%f",[maxLat floatValue]] forKey:@"maxlat"];
		[messageRequest setPostValue:[NSString stringWithFormat:@"%f",[minLong floatValue]] forKey:@"minlong"];
		[messageRequest setPostValue:[NSString stringWithFormat:@"%f",[maxLong floatValue]] forKey:@"maxlong"];
		[messageRequest setDelegate:self];
		[messageRequest startAsynchronous];
		//[messageRequest release];
		updating=YES;
		run=NO;
		num=0;
		NSLog(@"Table update complete");
		NSLog(@"%d",num);
		
	}
}

-(void)followTimerUpdate:(NSTimer*)theTimer
{
	if (num==1)
	{
		[theTimer invalidate];
		run=NO;
	}
	
	NSLog(@"The timer has updated");
	
	NSLog(@"%d%",num);
	
	NSMutableArray *latArray = [delegate latitudeCalculator];
	[self updateMessagesWithMinLatitude:[latArray objectAtIndex:0] 
						 andMaxLatitude:[latArray objectAtIndex:1]
						andMinLongitude:[latArray objectAtIndex:2] 
						andMaxLongitude:[latArray objectAtIndex:3]];
	NSLog(@"The timer has called the update function");
	
	NSLog(@"%d%",num);
}

-(void)startTimer {
	
	
	NSLog(@"The communication controller has initiated a 3.5 second timer to schedule message updates");
	[NSTimer scheduledTimerWithTimeInterval:3.5 target:self selector:@selector(followTimerUpdate:) userInfo:nil repeats:YES];
	
	num=0;
	
}
-(void)stopTimer
{
	
	num=1;
	NSLog(@"Stopping Timer");
	
}

- (void)sendMessageToServerWithLocation:(NSString *)location 
							   withText:(NSString *)text 
						   withLatitude:(NSString *)latitude 
						  withLongitude:(NSString *)longitude
							   withName:(NSString *)name
								withBio:(NSString *)bio
						
						 withDeviceUUID:(NSString *)deviceUUID


{
	
	if(!updating)
	{
		NSURL *url = [NSURL URLWithString:@"http://www.virtualcoachdesign.com/medalsend.php"];
		ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
		[request setPostValue:location forKey:@"location"];
		[request setPostValue:text forKey:@"text"];
		[request setPostValue:latitude forKey:@"latitude"];
		[request setPostValue:longitude forKey:@"longitude"];
		[request setPostValue:name forKey:@"name"];
		[request setPostValue:bio forKey:@"bio"];
		
		[request setPostValue:deviceUUID forKey:@"deviceUUID"];
		
		
		[request setDelegate:self];
		[request startAsynchronous];
		NSMutableArray *latArray = [delegate latitudeCalculator];
		[self updateMessagesWithMinLatitude:[latArray objectAtIndex:0]
							 andMaxLatitude:[latArray objectAtIndex:1]
							andMinLongitude:[latArray objectAtIndex:2] 
							andMaxLongitude:[latArray objectAtIndex:3]];
	}
	
}

-(void)followTimerUpdate1:(NSTimer*)theTimer
{
	run=NO;
}

-(void)startTimer2 {
	
	
	NSLog(@"1 second timer");
	[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(followTimerUpdate1:) userInfo:nil repeats:YES];
	
	num=0;
	
}

- (void)requestFinished:(id)request{
	
	//NSLog(@"%@",[request responseString]);
	if([[request responseString] isEqualToString:@"<noup>"]){
		// Do nothing, the server returned no output and we shouldn't update our tables
		updating=NO;
		NSLog(@"Server reported no update required (<noup>)");
		return;
	}
	else if([[request responseString] isEqualToString:@"<sent>"]){
		// Do nothing, the server returned that a message was sent so wait for the next tick to receive the new message
		NSLog(@"Server reported that the message was sent successfully (<sent>)");
		return;
	}
	
	// Default case, message data was received, parse it into messages
	
	NSData *messageData = [[request responseString] dataUsingEncoding:NSUTF8StringEncoding];
	NSError *errorStr = nil;
	NSPropertyListFormat format;
	NSArray *plistArray = [NSPropertyListSerialization propertyListWithData:messageData options:0 format:&format error:&errorStr];	
	
	if([plistArray count]==0){
		
		NSLog([request responseString]);
		updating=NO;
		run=YES;
		return;
	}
	
	NSMutableArray *newMessageArray = [[NSMutableArray alloc] init]; 
	//NSLog(@"the length of plistArray is %d",[plistArray count]);
	for(NSDictionary *messageDict in plistArray){
		Message *newMessage = [[Message alloc] init];
		newMessage.text = [messageDict objectForKey:@"text"];
		newMessage.location = [messageDict objectForKey:@"location"];
		newMessage.latitude = [[messageDict objectForKey:@"latitude"] floatValue];
		newMessage.longitude = [[messageDict objectForKey:@"longitude"] floatValue];
		newMessage.identifier = [[messageDict objectForKey:@"id"] intValue];
		newMessage.name = [messageDict objectForKey:@"name"];
		newMessage.bio = [messageDict objectForKey:@"bio"];
		
		newMessage.deviceUUID = [messageDict objectForKey:@"deviceUUID"];
		
		newMessage.visible = YES;
		//NSLog(@"inserting new message into new message array");
		[newMessageArray insertObject:newMessage atIndex:0];
		[newMessage release];
		
	}
	int endIndex = [newMessageArray count]-1;
	currentID=(int)[[newMessageArray objectAtIndex:endIndex] identifier];
	//NSLog(@"Array length:%d",[newMessageArray count]);
	[delegate messageUpdateComplete:newMessageArray];
	[newMessageArray release];
	updating=NO;
	run=YES;
	
	
	
}
-(void)dealloc
{
	[super dealloc];
	
}
@end
taylor202 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 325
15 members and 310 guests
7twenty7, chiataytuday, condor304, Creativ, Desert Diva, Domele, dreamdash3, laureix68, LEARN2MAKE, mistergreen2011, mottdog, palme2elie, Paul Slocum, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,660
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, laureix68
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:18 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0