memory-management

C++ passing struct or object by value

I have this: enum Units { Pounds, Kilos }; struct Configuration { const Units units; const char *name; inline Configuration(Units pUnits, char *pName) : units(pUnits) { name = strdup(pName); } inline ~Configuration() { free((void *)name); } }; I was passing one of these to a method like this: Config...

Java GC Question: How could an object become unreachable while one of its methods is still being executed?

I have been reading these slides about Java finalizers. In it, the author describes a scenario (on slide 33) whereby CleanResource.finalize() could be run by the finalizer thread while CleanResource.doSomething() is still running on another thread. How could this happen? If doSomething() is a non-static method, then to execute that me...

Is encapsulating Strings as byte[] in order to save memory overkill ? (Java)

Was recently reviewing some Java Swing code and saw this: byte[] fooReference; String getFoo() { returns new String(fooReference); } void setFoo(String foo) { this.fooReference = foo.getBytes(); } The above can be useful to save on your memory foot print or so I'm told. Is this overkill is anyone else encapsulating their St...

Memory release problems in Objective-C

I have a real-life example that I have in my project below. My aim is to pick out the most likely phone number for SMS receptions, and only that (phone)number. All works well when I don't release memory at the end, but we can't have that, can we. My question is: Where (and how) is the correct way to release memory in the example below? ...

Multiple MKOverlays on a MKMapView lead to memory warnings

I'm working on an iPhone app that shows a map with multiple circle overlays on certain locations. I'm running into serious memory issues and crashes when I add more than 6 circles and I zoom out far enough that they are all visible. When I zoom in such that only 2 circles are visible, all is fine. When I remove the MKOverlays, everythin...

What is better in terms of memory allocation - subobject or a pointer to a separate object?

I have the following problem in a Visual C++ 9 program. There's a huge object that logically contains several subobjects. I can either store the subobjects inside the object or store pointers to subobjects allocated separately. The key point here is that there's always one instance of suboject of each type in one outer object - it is al...

Is Clang Static Analyzer enough?

Hi guys, I'm new to iphone and objective-c development and want to ask if Clang Static Analyzer is enough for getting rid of memory leaks? I personally found the xcode "Leaks" tool rather difficult to use, besides I've seen some articles, where it reads that it will always show memory leaks, even if there are no any real leaks. If I don...

memory management

This is a memory management question about c++ code. using namespace std; #include <iostream> #include <string.h> int main() { string a="first"; string *b= new string; *b=a; a="second"; cout << *b << ", " << a; delete b; return 0; } We can deallocate the blocks of memory that stored the string that b pointed to. I'm assuming ...

IPhone Memory management and CATransition

Having some basic issues with managing the total memory from adding and removeing a uiviewcontroller - but only when i add an animation to it using CAtransition. I set up a simple scenario below of the situation: I have a basic view controller that I init/alloc called IVC, and I add to the current uiController: IN the header file it ...

Concept of allocating free memory

Hello, I would like to know how memory allocation on the lowest levels works. For example if program wants to create some long array or anything else, how it will ask for the memory, how does the program ensure itself that it does not take memory same other program is using. I would be very grateful if someone would bring some light fo...

Why is this NIB view not released before being returned?

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"ThemeCell" owner:self options:nil]; cell = self.themeCell; self.themeCell = nil; } ... return cell; My understanding is that self.themeCell = nil; should destroy the object sinc...

Is it better to store value as variable or call method again?

Recently, I started learning some Java. From what I've already learned about JVM it looks like JIT makes it pretty fast on operations requiring CPU cycles (i.e. calling a method) but also makes it hungry for memory. So when I need same output from same method as before, is it generally better approach to store the output from before in v...

Resizing a UIImage on the iPhone with a small memory footprint

I've seen this question asked dozens of times but never answered. How do you resize a UIImage (specifically one returned from the UIImagePickerController camera). When I try any of the methods that are out there I get a memory spike between 20 and 40MB. It does go away but I know that on some hardware this is completely unacceptable. I...

MPMoviePlayerController still leaking

I release the MPMoviePlayerController but the memory allocation and the living objects are sill higher than before the object allocation. However if i reallocate the object it doesn't leak more. My application actually uses alot of media files and the memory consumption it's high. I would like to free up completely the unneeded memory to...

Releasing static object

I know in vast of the cases I don't have to release static variable. However the following is the code for my model: + (UIImage*)imageForTag { static UIImage *imgTag; if(imgTag == nil) { NSString* imageName = [[NSBundle mainBundle] pathForResource:@"tag" ofType:@"png"]; imgTag = [[...

How does NSMutableData allocate memory?

When I run the following code, it slowly eats up my memory and even starts using swap: long long length = 1024ull * 1024ull * 1024ull * 2ull; // 2 GB db = [NSMutableData dataWithLength:length]; char *array = [db mutableBytes]; for(long long i = 0; i < length - 1; i++) { array[i] = i % 256; } If I run it without the for c...

iPhone Development - What can be done about this memory error:

Dual Search(8896,0xb014b000) malloc: *** error for object 0x5a1e0f0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Thanks! ...

memory mgmt problem in complex dictionary

I hate asking memory management questions - all the good answers are variations on RTFM. But this one is stumping me. I have a (relatively) complex dictionary in my model class, where each key points to an array of arrays. I constantly add and delete items to it, depending on state. Each "item" is an array. - (void)addToDictionary:(NSN...

Lazy Evaluation for iterating through NumPy arrays

I have a Python program that processes fairly large NumPy arrays (in the hundreds of megabytes), which are stored on disk in pickle files (one ~100MB array per file). When I want to run a query on the data I load the entire array, via pickle, and then perform the query (so that from the perspective of the Python program the entire array...

query regarding NSString object and memory management

I have the following piece of code: NSString *tempString = [[NSString alloc] initWithFormat:@"%d/%d/%d",day, month, year]; dateString = tempString; [tempString release]; NSLog(@"retain count for datstring and tempstring is %d and %d",[dateString retainCount],[tempString retainCount]); NSLog(@"%@ and %@",dateString, tempString) Now ...