2011-06-15 17 views
13

Estoy tratando de hacer una solicitud HTTP y analizar JSON utilizando la biblioteca JSON de Stig. Estoy recibiendo este error 'autorelease' no está disponible: no disponible en el modo de recuento de referencias automática cuando se utiliza este códigoerror 'liberación automática' no está disponible: no disponible en el modo de conteo de referencia automática

NSURLRequest *request2; 
request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://sandbox.CompanyName.com/api/%@/users/%@/user_badges?url=CompanyName.map2.com&amount=999999999999",[information stringForKey:@"apiKey"] , [information stringForKey:@"userID"]]]]; 

NSURLConnection *connection2; 
connection2 = [[NSURLConnection alloc] initWithRequest:request2 delegate:self startImmediately:YES]; 
NSURLResponse *resp2; 
NSData *cData2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:&resp2 error:nil]; 
NSString *cDataString2 = [[NSString alloc] initWithData:cData2 encoding:NSUTF8StringEncoding]; 
NSLog(@"getUsersBadges called"); 
NSError *error4; 
SBJSON *json4 = [[SBJSON new] autorelease]; 
// NSArray *luckyNumbers = [json objectWithString:responseString error:&error]; 
NSDictionary *luckyNumbers4 = [json4 objectWithString:cDataString2 error:&error4]; 

[cDataString2 release]; 

ACTUALIZACIÓN

Para todos los interesados, este es el código correcto : NSURLRequest * request2; request2 = [Petición NSURLRequestWithURL: [NSURL URLWithString: [NSString stringWithFormat: @ "http://sandbox.CompanyName.com/api/%@/users/%@/user_badges?url=CompanyName.map2.com&amount=999999999999", [información stringForKey: @ "apiKey"], [information stringForKey: @ "userID"]]]];

NSURLConnection *connection2; 
connection2 = [[NSURLConnection alloc] initWithRequest:request2 delegate:self startImmediately:YES]; 
NSURLResponse *resp2; 
NSData *cData2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:&resp2 error:nil]; 
NSString *cDataString2 = [[NSString alloc] initWithData:cData2 encoding:NSUTF8StringEncoding]; 
NSLog(@"getUsersBadges called"); 
NSError *error4; 
SBJSON *json4 = [SBJSON new]; 
// NSArray *luckyNumbers = [json objectWithString:responseString error:&error]; 
NSDictionary *luckyNumbers4 = [json4 objectWithString:cDataString2 error:&error4]; 
+1

La administración de la memoria ha cambiado mucho en iOS5 con la introducción del conteo automático de referencias. Necesita leer una buena introducción a ARC. Recomiendo [el tutorial de Ray Wenderlich] (http://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1) por Matthijs Hollemans. – Thilo

Respuesta

18

Cambio

SBJSON *json4 = [[SBJSON new] autorelease];

a

SBJSON *json4 = [SBJSON new];

Esto le permitirá salir de referencia automática contando intacta.

+0

¡Gran respuesta! Estaba evitando el problema al desactivar el conteo automático de referencias. ¡De hecho, esto muestra cómo solucionar el problema! –

23

La forma de deshacerse de este error es entrar en la configuración de compilación de proyectos. Busque el conteo automático de referencias. Una vez que encuentre que establece el valor a "NO"

+0

+1 me salvaste la vida gracias a U ...! – Dinesh

+0

+1 Gracias funcionó para mí mucho – Babul

Cuestiones relacionadas