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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Mac OS X Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-14-2010, 05:07 PM   #1 (permalink)
Anyone for iPad Dev?
 
Join Date: Sep 2009
Location: Take a Guess
Posts: 74
Default Memory error!

I have written code to see if a mp3 file is readable using NSFileManager. However, this string keeps throwing the program off. A MEMORY ERROR! Take a look:
Code:
//
//  Created by Will Estes on 1/13/10.
//  Copyright 2010 Fondu Development. All rights reserved.
//

#import "DRMinizerMACAppDelegate.h"

@implementation DRMinizerMACAppDelegate

@synthesize window,statusLabel,filePath;

- (BOOL)application:(NSApplication *)sender openFile:(NSString *)path
{
	
	filePath = [[NSString alloc]init];
	filePath = path;
	
	
	
	NSLog(@"%@",filePath);
	i = 1;
	[statusLabel setStringValue:@"Song Recieved!"];
	
	return YES;
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
	// Insert code here to initialize your application 
}

-(IBAction)stripDRM:(id)sender {
	
	NSLog(@"%@", filePath);
	
	if(i ==1) {
		
		i = 0;
	
		[self drmbgone:filePath];
		
	}
	
	

	
}

-(void)drmbgone:(NSString *)fp {
	
	NSLog(@"drmbgone");
	
	if ( [[NSFileManager defaultManager] isReadableFileAtPath:fp] )
		NSLog(@"path is readable");
		
}

@end
You drag a mp3 file to the dock to get the program to receive the path.
When you click the UI button, it sees if its readable. BUT THE FILEPATH STRING IS GETTING ME A MEMORY ERROR.

HERE IS WHAT THE STACK SAYS:
Code:
0x00007fff8689c0b6  <+0150>  callq  0x7fff86936b04 <dyld_stub_getpid>
Program receives SIGKILL

Please help!
fondu-Dev is offline   Reply With Quote
Old 01-14-2010, 05:47 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

The string you get is probably set to be autoreleased, but you never retain it - so it's gone when you go to use it. Replace these two lines:

Code:
	filePath = [[NSString alloc]init];
	filePath = path;
with this one
Code:
	filePath = [path retain];
By the way what you were doing - init'ing an empty string and then throwing it away to point to a different string - doen't work the way you think it does. It's like saying this:
Code:
	a=7
	a=5
The second line cancels out the first. Also it's rare to init an empty string, since they're immutable. You can't change the string later, all you can do is point the pointer at something new.
__________________

Free Games!

Last edited by smasher; 01-14-2010 at 05:49 PM.
smasher 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: 285
21 members and 264 guests
2WeeksToGo, ADY, apatsufas, ckgni, dacapo, Dani77, Fritzer, ghost, HDshot, headkaze, jakerocheleau, masc2279, mer10, mystic.purple, objch, Rudy, stoneage, tathaastu, themathminister, timle8n1, Zool
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,878
Threads: 89,224
Posts: 380,732
Top Poster: BrianSlick (7,129)
Welcome to our newest member, olga2000
Powered by vBadvanced CMPS v3.1.0

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