memory-management

Odd UITableView height behavior with NSZombieEnabled

I am setting my height: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { CGFloat rowHeight = 0; if(indexPath.row == [self.items count]){ //more rowHeight = 50.0; //same as moreCell } else{ ChartlyCell *cell = (ChartlyCell*)[self tableView:tblView cellFo...

What happens if a UITableViewCell is not released?

What will happen if the autorelease is removed from cell creation in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { STVCell *cell = (STVCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[STVCell alloc] initWi...

What are live bytes?

I have an app that holds a lot of pictures and when the user browses them the live bytes in my app gets to max 88 mb. firstly what does that me, The app doesnt crash, it gets a little slower. but is that 88mb in memory ? Secondly I have a UIView which I set its view to an image depending on the number in the counter. Is there a way to...

Possible scenarios of using alloc/retain/release on iPhone?

Hi, I have been using ojective c for almost a week, and I am mainly a c++ coder. After I read Apple's memory management guide, I try to bring my memory usage style in c++ into objective c... I tried to conclude these scenarios, I think I won't make memory mistake if I follow these instructions. Please kindly let me know if I am wrong :...

free() call works on simulator, makes iPad angry. iPad smash.

Hello, My app is running out of memory. To resolve this, I free up two very large arrays used in a function that writes a framebuffer to an image. The method looks like this: -(UIImage *) glToUIImage { NSInteger myDataLength = 768 * 1024 * 4; // allocate array and read pixels into it. GLubyte *buffer = (GLubyte *) malloc(my...

Possible to cast to pointer of given type determined at runtime in C?

I'm fairly sure the answer to this is 'no, don't be stupid', but as they say, there are no stupid questions (only stupid people asking them). I want to calculate the offset of an array. I have a void * handle to it and the sizeof(element). I don't have an x* pointer (where x is the type of the element). Is there any way I can cast the...

CUDA - Maintain pointers to global memory

I have a .NET program that is utilizing CUDA. The CUDA is accessed through a C DLL. What I am doing is initializing my CUDA application by allocating buffers (cudaMalloc) on the device at program startup. Pointers to these buffers are then maintained in static variables declared in the DLL. Data is copied to and from the buffers thro...

Where can I read more about memory structure in C++?

I came across this presentation while browsing SO some time ago, and it relates performance to specific memory allocation decisions. The author has some interesting diagrams that show how various objects are allocated by a C++ program, and goes on to optimise the program by making some changes in the code. His diagrams make sense in thei...

Cocoa/ObjC: Are there any performance drawbacks to my style of allocing objects for property iVars?

I use properties pretty much anytime my classes need iVars. For retained properties, I have grown accustomed to a specific way of using the accessor methods to alloc/initialize the actual iVars: - (void)anInitOrAccessorMethod { self.property = [[AClass alloc] init]; [self.property release]; } Anytime I need to set a non-autoreleas...

iPhone memory leak pointer

Hey guys, another memory management question: I have asked this before, but did not really get an answer: The question is would the following result in a leak or is it ok? NSArray *txtArray = [NSArray array]; NSString *aTxtFieldTxt = [[NSString alloc]initWithString:aTxtField.text]; aTxtFieldTxt = [aTxtFieldTxt stringByTrimmingCharacte...

A very basic question about alloc and release

Hi Forum I'm a little confused about objc and allocating/releasing objects. If I do this: NSString *myString; if([someString isEqualToString: @"test1"]){ myString = @"got 1"; }else{ myString = @"got 2"; } Do I have to release myString after that? And the same with self-defined objects: myOwnObject *someObject = [someArray...

Xcode's "build and analyze" reports odd memory leaks for this code

Does anyone know why xCode's "build and analyze" would report this line as a "possible memory leak"? goodSound = [[SoundClass alloc] initializeSound:@"Good.wav"]; ///// Here are the 4 files in question: // Sounds.h #import <Foundation/Foundation.h> #import <AudioToolbox/AudioToolbox.h> @interface SoundClass : NSObject { ...

How to avoid the "swapping of death" during development?

Probably everyone ran into this problem at least once during development: while(/*some condition here that somehow never will be false*/) { ... yourvector.push_back(new SomeType()); ... } As you see the program starts to drain all system memory, your program hangs and your system starts to swap like crazy. If you don't rec...

How do I tell how much memory / resources is my php script using up?

Hi guys I'm debugging my application here and basically in a nutshell - the application is dying out on my online server or maybe its my server dying out. But I have checked this application three different servers and all exhibited similar results, the application would run for a while but all of a sudden once I'd be opening more and mo...

Include statement taking up 1.5 MB of memory?

Hi guys I'm trying to optimize my application here and have started to benchmark snippets of code as to how much memory they are taking up. I just discovered that a single include statement is taking up to 1.5MB of memory. I'm using memory_get_usage() to check for memory used before adn after a snippet of code. The file included include...

Managed + unmanaged application causes memory leak

I have a wrapper managed application(.net) over a COM Component(created using vb6) where Com component also uses native c++ dll. Aplication runs as a background process and is supposed to run continously 24 X 7. The application runs fine for certain time, but after certain time it crashes. Possible reasons might be momory leak in c++ d...

How do I know if I need to alloc and if I need to release?

Completely new to Objective-C, trying to find out when I need to alloc and release objects. For example, I want to fetch some data from the Web. I found an article at Apple which has this code: NSURLRequest *theRequest=[NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.apple.com/"] cac...

In Objective C why are my core data objects never being deallocated?

I am having a lot of trouble getting m core data objects to be deallocated. I even tried the simplest test I could think of and I watched the retain count and it always seems to be higher than I expect. I also put a breakpoint on the dealloc routine for the core data objects and it doesn't seem to get called (at least not unless I specif...

iPhone, objective c reassign and return pointer of method

Hey guys, lately I have been asking quite a few questions about memory management on the iPhone. Fortunately things are getting clearer. But I still struggle when it gets more complex: So is there something wrong with this in terms of memory mangement? My question and suggestions are in the comments... //I get a text from a textfield NS...

PHP Memory Management

I have a few time-consuming and (potentially) memory-intensive functions in my LAMP web application. Most of these functions will be executed every minute via cron (in some cases, the cron job will execute multiple instances of these functions). Since memory is finite, I don't want to run into issues where I am trying to execute a funct...