Search Results

Search found 134 results on 6 pages for 'nsautoreleasepool'.

Page 2/6 | < Previous Page | 1 2 3 4 5 6  | Next Page >

  • Using Singleton synchronized array with NSThread

    - by hmthur
    I have a books app with a UISearchBar, where the user types any book name and gets search results (from ext API call) below as he types. I am using a singleton variable in my app called retrievedArray which stores all the books. @interface Shared : NSObject { NSMutableArray *books; } @property (nonatomic, retain) NSMutableArray *books; + (id)sharedManager; @end This is accessed in multiple .m files using NSMutableArray *retrievedArray; ...in the header file retrievedArray = [[Shared sharedManager] books]; My question is how do I ensure that the values inside retrievedArray remain synchronized across all the classes. Actually the values inside retrievedArray gets added through an NSXMLParser (i.e. through external web service API). There is a separate XMLParser.m file, where I do all the parsing and fill the array. The parsing is done on a separate thread. - (void) run: (id) param { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL: [self URL]]; [parser setDelegate: self]; [parser parse]; [parser release]; NSString *tmpURLStr = [[self URL]absoluteString]; NSRange range_srch_book = [tmpURLStr rangeOfString:@"v1/books"]; if (range_srch_book.location != NSNotFound) [delegate performSelectorOnMainThread:@selector(parseDidComplete_srch_book) withObject:nil waitUntilDone:YES]; [pool release]; } - (void) parseXMLFile: (NSURL *) url { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [self setURL: url]; NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object: nil]; [retrievedArray removeAllObjects]; [myThread start]; [pool release]; } There seems to be some synchronization issues if the user types very quickly (It seems to be working fine if the user types slowly)....So there are 2 views in which the content of an object in this shared array item is displayed; List and Detail. If user types fast and clicks on A in List view, he is shown B in detail view...That is the main issue. I have tried literally all the solutions I could think of, but am still unable to fix the issue. Please suggest some suitable fixes.

    Read the article

  • What (tf) are the secrets behind PDF memory allocation (CGPDFDocumentRef)

    - by Kai
    For a PDF reader I want to prepare a document by taking 'screenshots' of each page and save them to disc. First approach is CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef) someURL); for (int i = 1; i<=pageCount; i++) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; CGPDFPageRef page = CGPDFDocumentGetPage(document, i); ...//getting + manipulating graphics context etc. ... CGContextDrawPDFPage(context, page); ... UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); ...//saving the image to disc [pool drain]; } CGPDFDocumentRelease(document); This results in a lot of memory which seems not to be released after the first run of the loop (preparing the 1st document), but no more unreleased memory in additional runs: MEMORY BEFORE: 6 MB MEMORY DURING 1ST DOC: 40 MB MEMORY AFTER 1ST DOC: 25 MB MEMORY DURING 2ND DOC: 40 MB MEMORY AFTER 2ND DOC: 25 MB .... Changing the code to for (int i = 1; i<=pageCount; i++) { CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef) someURL); NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; CGPDFPageRef page = CGPDFDocumentGetPage(document, i); ...//getting + manipulating graphics context etc. ... CGContextDrawPDFPage(context, page); ... UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); ...//saving the image to disc CGPDFDocumentRelease(document); [pool drain]; } changes the memory usage to MEMORY BEFORE: 6 MB MEMORY DURING 1ST DOC: 9 MB MEMORY AFTER 1ST DOC: 7 MB MEMORY DURING 2ND DOC: 9 MB MEMORY AFTER 2ND DOC: 7 MB .... but is obviously a step backwards in performance. When I start reading a PDF (later in time, different thread) in the first case no more memory is allocated (staying at 25 MB), while in the second case memory goes up to 20 MB (from 7). In both cases, when I remove the CGContextDrawPDFPage(context, page); line memory is (nearly) constant at 6 MB during and after all preparations of documents. Can anybody explain whats going on there?

    Read the article

  • Multithreaded search with UISearchDisplayController

    - by Kulpreet
    I'm sort of new to any sort of multithreading and simply can't seem to get a simple search method working on a background thread properly. Everything seems to be in order with an NSAutoreleasePool and the UI being updated on the main thread. The app doesn't crash and does perform a search in the background but the search results yield the several of the same items several times depending on how fast I type it in. The search works properly without the multithreading (which is commented out), but is very slow because of the large amounts of data I am working with. Here's the code: - (void)filterContentForSearchText:(NSString*)searchText { NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init]; isSearching = YES; //[self.filteredListContent removeAllObjects]; // First clear the filtered array. for (Entry *entry in appDelegate.entries) { NSComparisonResult result = [entry.item compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame) { [self.filteredListContent addObject:entry]; } } isSearching=NO; [self.searchDisplayController.searchResultsTableView performSelectorOnMainThread:(@selector(reloadData)) withObject:nil waitUntilDone:NO]; //[self.searchDisplayController.searchResultsTableView reloadData]; [apool drain]; } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(filteredListContent:) object:searchString]; [self.filteredListContent removeAllObjects]; // First clear the filtered array. [self performSelectorInBackground:(@selector(filterContentForSearchText:)) withObject:searchString]; //[self filterContentForSearchText:searchString]; // Return YES to cause the search result table view to be reloaded. return NO; }

    Read the article

  • Xcodebuild throws assert failures after successful build?

    - by Derek Clarkson
    Hi all, I'me getting the following after building from he command line using xcodebuild, ay ideas what might be wrong? ** BUILD SUCCEEDED ** 2010-06-06 20:20:12.916 xcodebuild[8267:80b] [MT] ASSERTION FAILURE in /SourceCache/DevToolsBase/DevToolsBase-1648/pbxcore/Target.subproj/PBXTarget.m:597 Details: Assertion failed: (nil == _buildContext) || (nil == [_buildContext target]) Object: <PBXLegacyTarget:0x104b97370> Method: -dealloc Thread: <NSThread: 0x100b141a0>{name = (null), num = 1} Backtrace: 0 0x000000010035feaf -[XCAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in DevToolsCore) 1 0x000000010035fc1a _XCAssertionFailureHandler (in DevToolsCore) 2 0x00000001002790d1 -[PBXTarget dealloc] (in DevToolsCore) 3 0x00000001002911e8 -[PBXLegacyTarget dealloc] (in DevToolsCore) 4 0x00000001002c5b16 -[PBXTargetBookmark dealloc] (in DevToolsCore) 5 0x00007fff8224ff71 __CFBasicHashStandardCallback (in CoreFoundation) 6 0x00007fff82250931 __CFBasicHashDrain (in CoreFoundation) 7 0x00007fff822396b3 _CFRelease (in CoreFoundation) 8 0x0000000100254171 -[PBXProject dealloc] (in DevToolsCore) 9 0x00007fff82262d56 _CFAutoreleasePoolPop (in CoreFoundation) 10 0x00007fff841b530c -[NSAutoreleasePool drain] (in Foundation) 11 0x000000010000c60d 12 0x00000001000014f4 ** INTERNAL ERROR: Uncaught Exception ** Exception: ASSERTION FAILURE in /SourceCache/DevToolsBase/DevToolsBase-1648/pbxcore/Target.subproj/PBXTarget.m:597 Details: Assertion failed: (nil == _buildContext) || (nil == [_buildContext target]) Object: <PBXLegacyTarget:0x104b97370> Method: -dealloc Thread: <NSThread: 0x100b141a0>{name = (null), num = 1} Backtrace: 0 0x000000010035feaf -[XCAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in DevToolsCore) 1 0x000000010035fc1a _XCAssertionFailureHandler (in DevToolsCore) 2 0x00000001002790d1 -[PBXTarget dealloc] (in DevToolsCore) 3 0x00000001002911e8 -[PBXLegacyTarget dealloc] (in DevToolsCore) 4 0x00000001002c5b16 -[PBXTargetBookmark dealloc] (in DevToolsCore) 5 0x00007fff8224ff71 __CFBasicHashStandardCallback (in CoreFoundation) 6 0x00007fff82250931 __CFBasicHashDrain (in CoreFoundation) 7 0x00007fff822396b3 _CFRelease (in CoreFoundation) 8 0x0000000100254171 -[PBXProject dealloc] (in DevToolsCore) 9 0x00007fff82262d56 _CFAutoreleasePoolPop (in CoreFoundation) 10 0x00007fff841b530c -[NSAutoreleasePool drain] (in Foundation) 11 0x000000010000c60d 12 0x00000001000014f4 Stack: 0 0x00007fff822ded06 __exceptionPreprocess (in CoreFoundation) 1 0x00007fff832470f3 objc_exception_throw (in libobjc.A.dylib) 2 0x00007fff823369b9 -[NSException raise] (in CoreFoundation) 3 0x000000010035ff6a -[XCAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in DevToolsCore) 4 0x000000010035fc1a _XCAssertionFailureHandler (in DevToolsCore) 5 0x00000001002790d1 -[PBXTarget dealloc] (in DevToolsCore) 6 0x00000001002911e8 -[PBXLegacyTarget dealloc] (in DevToolsCore) 7 0x00000001002c5b16 -[PBXTargetBookmark dealloc] (in DevToolsCore) 8 0x00007fff8224ff71 __CFBasicHashStandardCallback (in CoreFoundation) 9 0x00007fff82250931 __CFBasicHashDrain (in CoreFoundation) 10 0x00007fff822396b3 _CFRelease (in CoreFoundation) 11 0x0000000100254171 -[PBXProject dealloc] (in DevToolsCore) 12 0x00007fff82262d56 _CFAutoreleasePoolPop (in CoreFoundation) 13 0x00007fff841b530c -[NSAutoreleasePool drain] (in Foundation) 14 0x000000010000c60d 15 0x00000001000014f4 Abort trap

    Read the article

  • iPhone Multithreaded Search

    - by Kulpreet
    I'm sort of new to any sort of multithreading and simply can't seem to get a simple search method working on a background thread properly. Everything seems to be in order with an NSAutoreleasePool and the UI being updated on the main thread. The app doesn't crash and does perform a search in the background but the search results yield the several of the same items several times depending on how fast I type it in. The search works properly without the multithreading (which is commented out), but is very slow because of the large amounts of data I am working with. Here's the code: - (void)filterContentForSearchText:(NSString*)searchText { isSearching = YES; NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init]; /* Update the filtered array based on the search text and scope. */ //[self.filteredListContent removeAllObjects]; // First clear the filtered array. for (Entry *entry in appDelegate.entries) { NSComparisonResult result = [entry.gurmukhiEntry compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame) { [self.filteredListContent addObject:entry]; } } [self.searchDisplayController.searchResultsTableView performSelectorOnMainThread:(@selector(reloadData)) withObject:nil waitUntilDone:NO]; //[self.searchDisplayController.searchResultsTableView reloadData]; [apool drain]; isSearching = NO; } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { if (!isSearching) { [self.filteredListContent removeAllObjects]; // First clear the filtered array. [self performSelectorInBackground:(@selector(filterContentForSearchText:)) withObject:searchString]; } //[self filterContentForSearchText:searchString]; return NO; // Return YES to cause the search result table view to be reloaded. }

    Read the article

  • Gradual memory leak and slowdown in loop

    - by Benji XVI
    I have a simple foundation tool that exports every frame of a movie as a .tiff file. Here is the relevant code: NSString* movieLoc = [NSString stringWithCString:argv[1]]; QTMovie *sourceMovie = [QTMovie movieWithFile:movieLoc error:nil]; int i=0; while (QTTimeCompare([sourceMovie currentTime], [sourceMovie duration]) != NSOrderedSame) { // save image of movie to disk NSAutoreleasePool *arp = [[NSAutoreleasePool alloc] init]; NSString *filePath = [NSString stringWithFormat:@"/somelocation_%d.tiff", i++]; NSData *currentImageData = [[sourceMovie currentFrameImage] TIFFRepresentation]; [currentImageData writeToFile:filePath atomically:NO]; NSLog(@"%@", filePath); [sourceMovie stepForward]; [arp release]; } [pool drain]; return 0; As you can see, in order to prevent very large memory buildups with the various transparently-autoreleased variables in the loop, we create, and flush, an autoreleasepool with every run through the loop. However, over the course of stepping through a movie, the amount of memory used by the program still gradually increases, and the speed at which frames are processed drops precipitously. (From ~0.5 seconds per frame at the start, to ~2 seconds per frame by the 250th frame.) The only thing I can think can be causing the gradual memory leak is a buildup of the NSAutoreleasePool objects themselves. Am I right in thinking they will only be deallocated when the outer pool is released? If so, is there a better memory management solution here? Creating a pool every run through the loop seems a little hacky. And if not, what is causing the slow memory leak? (It is not NSStrings, and much too slow to be NSImages or NSDatas.) And what could be causing the slowdown?

    Read the article

  • How to solve a deallocated connection in iPhone SDK 3.1.3? - Streams - CFSockets

    - by Christian
    Hi everyone, Debugging my implementation I found a memory leak issue. I know where is the issue, I tried to solve it but sadly without success. I will try to explain you, maybe someone of you can help with this. First I have two classes involved in the issue, the publish class (where publishing the service and socket configuration is done) and the connection (where the socket binding and the streams configuration is done). The main issue is in the connection via native socket. In the 'publish' class the "server" accepts a connection with a callback. The callback has the native-socket information. Then, a connection with native-socket information is created. Next, the socket binding and the streams configuration is done. When those actions are successful the instance of the connection is saved in a mutable array. Thus, the connection is established. static void AcceptCallback(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info) { Publish *rePoint = (Publish *)info; if ( type != kCFSocketAcceptCallBack) { return; } CFSocketNativeHandle nativeSocketHandle = *((CFSocketNativeHandle *)data); NSLog(@"The AcceptCallback was called, a connection request arrived to the server"); [rePoint handleNewNativeSocket:nativeSocketHandle]; } - (void)handleNewNativeSocket:(CFSocketNativeHandle)nativeSocketHandle{ Connection *connection = [[[Connection alloc] initWithNativeSocketHandle:nativeSocketHandle] autorelease]; // Create the connection if (connection == nil) { close(nativeSocketHandle); return; } NSLog(@"The connection from the server was created now try to connect"); if ( ! [connection connect]) { [connection close]; return; } [clients addObject:connection]; //save the connection trying to avoid the deallocation } The next step is receive the information from the client, thus a read-stream callback is triggered with the information of the established connection. But when the callback-handler tries to use this connection the error occurs, it says that such connection is deallocated. The issue here is that I don't know where/when the connection is deallocated and how to know it. I am using the debugger, but after some trials, I don't see more info. void myReadStreamCallBack (CFReadStreamRef stream, CFStreamEventType eventType, void *info) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; Connection *handlerEv = [[(Connection *)info retain] autorelease]; // The error -[Connection retain]: message sent to deallocated instance 0x1f5ef0 (Where 0x1f5ef0 is the reference to the established connection) [handlerEv readStreamHandleEvent:stream andEvent:eventType]; [pool drain]; } void myWriteStreamCallBack (CFWriteStreamRef stream, CFStreamEventType eventType, void *info){ NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init]; Connection *handlerEv = [[(Connection *)info retain] autorelease]; //Sometimes the error also happens here, I tried without the pool, but it doesn't help neither. [handlerEv writeStreamHandleEvent:eventType]; [p drain]; } Something strange is that when I run the debugger(with breakpoints) everything goes well, the connection is not deallocated and the callbacks work fine and the server is able to receive the message. I will appreciate any hint!

    Read the article

  • loading 60 images locally fast is it possible...? [closed]

    - by Tariq- iPHONE Programmer
    when my app starts it loads 60 images at a time in UIImageView and it also loads a background music. in simulator it works fine but in IPAD it crashes.. -(void)viewDidLoad { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //img.animationImages = [[NSArray arrayWithObjects: MyImages = [NSArray arrayWithObjects: //[UIImage imageNamed: @"BookOpeningB001.jpg"],...... B099,nil]; //[NSTimer scheduledTimerWithTimeInterval: 8.0 target:self selector:@selector(onTimer) userInfo:nil repeats:NO]; img.animationImages = MyImages; img.animationDuration = 8.0; // seconds img.animationRepeatCount = 1; // 0 = loops forever [img startAnimating]; [self.view addSubview:img]; [img release]; [pool release]; //[img performSelector:@selector(displayImage:) ]; //[self performSelector:@selector(displayImage:) withObject:nil afterDelay:10.0]; [self performSelector: @selector(displayImage) withObject: nil afterDelay: 8.0]; } -(void)displayImage { SelectOption *NextView = [[SelectOption alloc] initWithNibName:nil bundle:nil]; [self presentModalViewController:NextView animated:NO]; [NextView release]; } Am i doing anything wrong ? Is there any other alternative to load the local images faster in UIImageView !

    Read the article

  • iPhone Gameloop render update from a separate thread

    - by Rich
    Hi, I'm new to iPhone development. I have a game loop setup as follows. (void)CreateGameTick:(NSTimeInterval) in_time { [NSThread detachNewThreadSelector:@selector(GameTick) toTarget:self withObject:nil]; } My basic game tick/render looks like this (void)GameTick { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; CGRect wrect = [self bounds]; while( m_running ) { [self drawRect: wrect]; } [pool release]; } My render function gets called. However nothing gets drawn (I am using Core Graphics to draw some lines on a derived UIView). If I call my update via a timer then all is well and good. Can you tell me why the render fails when done via threads? And is it possible to make it work via threads? Thanks Rich

    Read the article

  • Unable to find standard libraries when compiling Objective-C using GNUstep on Windows

    - by Jason Roberts
    I just installed GNUstep on my Windows XP machine and I'm attempting to compile the following Objective-C Hello World program from the command line: #import <Foundation/Foundation.h> int main(int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello world\n"); [pool drain]; return 0; } When I try to compile the program from the command line like so gcc hello.m -o hello I end up getting the following error hello.m:1:34: Foundation/Foundation.h: No such file or directory Is there something I need to do order to inform the compiler of where the standard Objective-C libraries are located?

    Read the article

  • nsthread in iphone xcode

    - by BibiBuBu
    Good Day! i want to use nsthreads in a project of xcode that will call a function which is for the network access and will check that if the network is there or not, so i need to have a thread which will execute after lets say 1 minutes to check the connectivity. and will continue run unless the app is closed. [NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil]; startTheBackgroundJob NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // wait for 3 seconds before starting the thread, you don't have to do that. This is just an example how to stop the NSThread for some time [NSThread sleepForTimeInterval:5]; //[self performSelectorInBackground:@selector(checkNet) withObject:nil]; [self performSelectorOnMainThread:@selector(checkNet) withObject:nil waitUntilDone:YES]; [pool release]; it works only for the first time but not any other, i mean only 1 loop it makes can somebody help me in this regard. Thanks

    Read the article

  • iphone Dev - activity indicator with NSThread not working on Nav controller table view

    - by Frames84
    I really can't get this to work, basically when my JSON feeds loads I want the indicator to show, then hide when it's stopped. It loads top level menu items 1st "Publishing, Broadcasting, Marketing Services", then when Broadcasting is selected it loads a feed using the JSON framework hosted on Google. Round this load I call startIndicator and stopIndicator using the NSThread. Have I missed something? @implementation GeneralNewsTableViewController @synthesize dataList; @synthesize generalNewsDetailViewController; @synthesize atLevel; -(void) startIndicator { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc ] init ]; [(UIActivityIndicatorView *)[self navigationItem].rightBarButtonItem.customView startAnimating]; [pool release]; } -(void) stopIndicator { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc ] init ]; [(UIActivityIndicatorView *)[self navigationItem].rightBarButtonItem.customView stopAnimating]; [pool release]; } - (void)viewDidLoad { NSMutableArray *checker = self.dataList; if(checker == nil) { self.title = NSLocalizedString(@"General1",@"General News"); NSMutableArray *array = [[NSArray alloc] initWithObjects:@"Publishing", @"Broadcasting",@"Marketing Services",nil]; self.dataList = [array retain]; self.atLevel = @"level1"; [array release]; } UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; //set the initial property [activityIndicator stopAnimating]; [activityIndicator hidesWhenStopped]; //Create an instance of Bar button item with custome view which is of activity indicator UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator]; //Set the bar button the navigation bar [self navigationItem].rightBarButtonItem = barButton; //Memory clean up [activityIndicator release]; [barButton release]; [super viewDidLoad]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *level = self.atLevel; if([level isEqualToString:@"level2"]) { return 70.0f; } else { return 40.0f; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *FirstLevelCell = @"FirstLevelCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FirstLevelCell]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:FirstLevelCell] autorelease]; } NSInteger row = [indexPath row]; NSString *level = self.atLevel; if([level isEqualToString:@"level2"]) { NSMutableArray *stream = [self.dataList objectAtIndex:row]; NSString *newsTitle = [stream valueForKey:@"title"]; if( ![newsTitle isKindOfClass:[NSString class]] ) { cell.textLabel.text = @""; } else { cell.textLabel.text = [stream valueForKey:@"title"]; } cell.textLabel.numberOfLines = 2; cell.textLabel.font =[UIFont systemFontOfSize:10]; cell.detailTextLabel.numberOfLines = 1; cell.detailTextLabel.font= [UIFont systemFontOfSize:8]; cell.detailTextLabel.text = [stream valueForKey:@"created"]; NSData *imageURL = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.how-do.co.uk/images/stories/Cimex.jpg"]]; UIImage *newsImage = [[UIImage alloc] initWithData:imageURL]; cell.imageView.image = newsImage; [imageURL release]; [newsImage release]; } else { cell.textLabel.text = [dataList objectAtIndex:row]; } return cell; } - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row = [indexPath row]; NSMutableString *levelType = (NSMutableString *) [dataList objectAtIndex:row]; if(![levelType isKindOfClass:[NSString class]]) { if(self.generalNewsDetailViewController == nil) { GeneralNewsDetailViewController *generalDetail = [[GeneralNewsDetailViewController alloc] initWithNibName:@"GeneralNewsDetailView" bundle:nil]; self.generalNewsDetailViewController = generalDetail; [generalDetail release]; } NSDictionary *stream = [self.dataList objectAtIndex:row]; NSString *newsTitle = [stream valueForKey:@"title"]; if( ![newsTitle isKindOfClass:[NSString class]] ) { generalNewsDetailViewController.newsTitle = @""; } else { generalNewsDetailViewController.newsTitle =[stream valueForKey:@"title"]; } generalNewsDetailViewController.newsId = [stream valueForKey:@"id"]; generalNewsDetailViewController.fullText = [stream valueForKey:@"fulltext"]; generalNewsDetailViewController.newsImage = [stream valueForKey:@"images"]; generalNewsDetailViewController.created = [stream valueForKey:@"created"]; HowDo_v1AppDelegate *delegate = [[UIApplication sharedApplication] delegate]; [delegate.generalNewsNavController pushViewController:self.generalNewsDetailViewController animated:YES]; } else { GeneralNewsTableViewController *generalSubDetail = [[GeneralNewsTableViewController alloc] initWithNibName:@"GeneralNewsTableView" bundle:nil]; NSMutableArray *array; NSString *titleSelected = (NSString *) [dataList objectAtIndex:row]; if([titleSelected isEqualToString:@"Publishing"]) { generalSubDetail.title = @"Publishing news detail"; array = [[NSArray alloc] initWithObjects:@"pub News1", @"pub News2",@"pub News3",nil]; generalSubDetail.atLevel = @"level1"; } else if ([titleSelected isEqualToString:@"Broadcasting"]) { generalSubDetail.title = @"Broadcasting news detail"; /// START [self performSelectorOnMainThread:@selector(startIndicator) withObject:nil waitUntilDone:YES]; if(jSONDataAccessWrapper == nil) { jSONDataAccessWrapper = [JSON_DataAccess_Wrapper alloc]; } array = [jSONDataAccessWrapper downloadJSONFeed]; [self performSelectorOnMainThread:@selector(stopIndicator) withObject:nil waitUntilDone:YES]; generalSubDetail.atLevel = @"level2"; } else if ([titleSelected isEqualToString:@"Marketing Services"]) { generalSubDetail.title = @"Marketing Services news detail"; array = [[NSArray alloc] initWithObjects:@"Marketing News1", @"Marketing News2",@"Marketing News3",nil]; generalSubDetail.atLevel = @"level1"; } generalSubDetail.dataList = array; [self.navigationController pushViewController:generalSubDetail animated:YES]; [titleSelected release]; } } - (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section //- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSIndexPath *) section { return [self.dataList count]; } Cheers for any feedback Frames

    Read the article

  • HOM with Objective C

    - by Coxer
    Hey, i am new to objective C, but i tried to use HOM in order to iterate over an NSArray and append a string to each element. here is my code: void print( NSArray *array ) { NSEnumerator *enumerator = [array objectEnumerator]; id obj; while ( nil!=(obj = [enumerator nextObject]) ) { printf( "%s\n", [[obj description] cString] ); } } int main( int argc, const char *argv[] ) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSArray *names = [[NSArray alloc] init]; NSArray *names_concat = [[NSArray alloc] init]; names = [NSArray arrayWithObjects:@"John",@"Mary",@"Bob",nil]; names_concat = [[names collect] stringByAppendingString: @" Doe"]; print(names_concat); [pool release]; } What is wrong with this code? My compiler (gcc) says NSArray may not respond to "-collect"

    Read the article

  • UISearch bar case sensitive off ? ? ?

    - by Flodev03
    hi all, in a table view i have set a UISearchBar set the delegate and add the protocol. When user tap a word everything is ok exept that the search of "tennis" and "Tennis" is not the same. How can i make the search bar a non case sensitive UISearchBar, i have search a lot please help it would be great thanks to all here is my code where i think evrything happens : thanks to all !!!! - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { [tableData removeAllObjects];// remove all data that belongs to previous search if([searchText isEqualToString:@""]||searchText==nil){ [myTableView reloadData]; return; } NSInteger counter = 0; for(NSString *name in dataSource) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; NSRange r = [name rangeOfString:searchText]; if(r.location != NSNotFound) [tableData addObject:name]; counter++; [pool release]; } [myTableView reloadData]; }

    Read the article

  • PerformSelectorInBackground leaking on device

    - by Oysio
    While it seems to not pose a problem on the simulator, using performSelectorInBackground on the device causes memory leaks. Or at least that's what Instruments indicates. Looking at the code I don't have a single clue what the cause could be. I tried to strip the affected code to a bare minimum but still strangely Instruments keeps showing a leak every time this piece of code is executed. Anything unusual going on here? //In viewcontrollerA: -(void)mainLoop { [self.viewControllerB performSelectorInBackground:@selector(calculateTotals) withObject:nil]; //This gives the same problem //[NSThread detachNewThreadSelector:@selector(calculateTotals) toTarget:self.viewControllerB withObject:nil]; //UI stuff ... } //viewControllerB: -(void)calculateTotals { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //Heavy calculations ... [pool release]; }

    Read the article

  • UIIMageView, warning: check_safe_call: could not restore current frame

    - by lukya
    Hi, I am changing the image in UIImageView based on accelerometer input. The images are stored in an array. The application runs fine for a while and then crashes. warning: check_safe_call: could not restore current frame I am not using "UIImage ImageNamed" method when populating the array. The total size of all images is around 12 Mb. But individual images are very light (<100 kb) and i am using only one image at a time from the array. Just in case there are any autoreleases, I have allocated a NSAutoreleasePool in view did load and am draining it in the didReceiveMemoryWarning method (which does get called 2, 3 times before the app crashes?). Following is the code that creates images array: //create autorelease pool as we are creating many autoreleased objects NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSMutableArray *finalarr = [[NSMutableArray alloc] initWithCapacity:9]; NSLog(@"start loading"); for(int y = 0; y < 100; y+=10) { NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:10]; for(int x = 0; x < 10; x++) { NSString *imageName = [[NSString alloc] initWithFormat:@"0%d",y + x]; UIImage *img = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]]; [arr addObject:img]; [imageName release]; [img release]; } [finalarr addObject:arr]; [arr release]; } NSLog(@"done loading"); // Override point for customization after app launch viewController.imagesArray = finalarr; [finalarr release]; //retain the array of images [viewController.imagesArray retain]; //release the aurtorelease pool to free memory taken up by objects enqued for release [pool release]; As the app runs smoothly for a while, which means array creation is definitely not the problem. After this the following method is called from [accelerometer didAccelerate] -(BOOL)setImageForX:(int)x andY:(int)y { [self.imageView setImage:(UIImage*)[(NSArray*)[self.imagesArray objectAtIndex:y] objectAtIndex:x]]; return TRUE; } So the only code being executed is the "UIImageView setImage". But no objects are being created here. Please let me know if the code seems to have any leaks or i am doing something wrong. Thanks, Swapnil

    Read the article

  • If the UIApplicationMain() never returns then when does the autorelease pool gets released?

    - by sid
    For code: int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } Apple's doc clearly specifies: Return Value: Even though an integer return type is specified, this function never returns. When users terminate an iPhone application by pressing the Home button, the application immediately exits by calling the exit system function with an argument of zero. Secondly, in int UIApplicationMain ( int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName ); how can we access the argv from our UIApplication subclass?

    Read the article

  • Memory over-release problem when I am animating UIView

    - by Sheehan Alam
    I have enabled NSZombie's and I am getting the following message in my console when I am running my application: *** -[UIViewAnimationState release]: message sent to deallocated instance 0xf96d7e0 Here is the method that is performing the animation -(void)loadAvatar:(STObject*)st { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; avatar.alpha = 0; avatar.frame = avatarRectSmall; avatar.image = [ImageCache getMemoryCachedImageAtUrl:st.avatar_url]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.50]; avatar.frame = avatarRectNormal; [avatar setAlpha:1]; [UIView commitAnimations]; [pool release]; pool = nil; } I don't always get a crash, only sometimes. I'm wondering what is getting released?

    Read the article

  • Application crashes when running in iPhone simulator 3.2 (Works fine in simulator 3.0)

    - by amitabh
    I just upgraded to SDK 3.2. My application runs in Simulator 3.0 in debug mode but when I change the Simulator to run with 3.2 it crashes with EXEC_BAD_ACCESS. It is crashing at objc_msgsend method. int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); <======== THE STACK TRACE starts here. [pool release]; return retVal; } Any idea what is going on? I have absolutely no clue. Any help/suggestion will be greatly appreciated? Thanks A

    Read the article

  • Regarding Debugging in Xcode

    - by user185590
    #import <Foundation/Foundation.h> @interface ClassA : NSObject { int x; } -(void) initVar; @end @implementation ClassA -(void) initVar { x = 100; } @end @interface ClassB : ClassA { int y; } -(void) initVar; -(void) printVar; @end @implementation ClassB -(void) initVar { x = 200; y = 300; } - (void) printVar { NSLog(@"x= %i", x ); NSLog(@"y= %i", y); } @end int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; ClassB * b = [[ClassB alloc] init]; [b initVar]; [b printVar]; [b release]; [pool drain]; return 0; }

    Read the article

  • My Thread Programs Crash

    - by zp26
    I have a problem with threads objectiveC. The line of code below contains the recv block the program waiting for a datum. My intention is to launch a thread parallel to the program so that this statement does not block any application. I put this code in my program but when active switch the program crashes. Enter the code. -(IBAction)Chat{ if(switchChat.on){ buttonInvio.enabled = TRUE; fieldInvio.enabled = TRUE; [NSThread detachNewThreadSelector:@selector(riceviDatiServer) toTarget:self withObject:nil]; } else { buttonInvio.enabled = FALSE; fieldInvio.enabled = FALSE; } -(void)riceviDatiServer{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; int ricevuti; NSString *datiRicevuti; ricevuti = recv(temp, &datiRicevuti, datiRicevuti.length, 0); labelRicezione.text = [[NSString alloc] initWithFormat:@"%s.... %d", datiRicevuti, ricevuti]; [pool release]; }

    Read the article

  • Keep a reference to an NSThread around and message its objects?

    - by RickiG
    Hi I am a bit uncertain on how to do this: I start a "worker-thread" that runs for the duration of my apps "life". [NSThread detachNewThreadSelector:@selector(updateModel) toTarget:self withObject:nil]; then - (void) updateModel { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; BackgroundUpdate *update = [[BackgroundUpdate alloc] initWithTimerInterval:5]; [[NSRunLoop currentRunLoop] run]; //keeps it going 'forever' [update release]; [pool release]; } Now the thread "wakes" up every 5 seconds(initWithTimerInterval) to see if there are any tasks it can do. All the tasks in the BackGroundUpdate Class are only time dependent for now. I would like to have a few that were "event dependent". e.g. I would like to call the Background Object from my main thread and tell it to "speedUp", "slowDown", "reset" or any method on the object. To do this I guess I need something like performSelectorOnThread but how to get a reference to the NSthread and the Background Object?

    Read the article

  • What system does before launching iPhone app's main() function?

    - by Eonil
    My app takes too much time to loading. So I put a NSLog in main() function like this to measure loading time from first: int main(int argc, char *argv[]) { NSLog(@"main"); NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } But, the log displayed at really later time. Default.png displayed about 5 seconds, all loading process completed in 1~2 seconds after log appeared. What's happening before executing main() function on iPhone app?

    Read the article

  • incorrect variable value outside main()

    - by cru3l
    i have this code #import <Foundation/Foundation.h> int testint; NSString *teststring; int Test() { NSLog(@"%d",testint); NSLog(@"%@",teststring); } int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; testint = 5; NSString *teststring = [[NSString alloc] initWithString:@"test string"]; Test(); [pool drain]; return 0; } in output i have: 5 (null) why Test function doesn't see correct teststring value? What should I do, to have correct "test string" in output?

    Read the article

  • CoreData leak when reading a property

    - by Kamchatka
    Hello, I have the following code in a loop iterating over the different document objects: NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; [document primitiveValueForKey:@"data"]; [data writeToFile:filename atomically:NO]; [document.managedObjectContext refreshObject:document mergeChanges:NO]; [pool release]; The "data" property is a large blob (a 1MB image). And as I monitor the memory with the Allocation Instrument memory usage is increasing. I cannot find where the leak is coming from and how to remove it. Thanks!

    Read the article

< Previous Page | 1 2 3 4 5 6  | Next Page >