memory-management

What's the best way to handle this "try - error - clean -retry" case?

I am trying to load an image in memory but might have memory issues since i have some other images loaded. These images have a "visible" field that dictates whether they are visible or not. Regardless of the visibility i keep them in memory for fast loading (when they become visible again). But since i have many of them in memory i wan...

C memory management error?

This is my C program: #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> #include <ctype.h> #define FALSE 0 #define TRUE 1 typedef struct _Frag { struct _Frag *next; char *seq; int x1; int length; } Frag; typedef struct _Fragment { int type; Frag *frag_list; } Fragment; static void free_frags (Fr...

Is MKMapView leaky

As well as my question "Removing MKMapView Annotations causes leaks." I have discovered that if you create a view based project, add a UISearchBar and MKMapView into the view's NIB, wire up the delegates (I'm not creating any methods as we don't actually need to do anything to trigger the leaks), link in the MapKit and fire up the proje...

Persistence scheme & state data for low memory situations (iphone)

What happens to state information held by a class's variable after coming back from a low memory situation? I know that views will get unloaded and then reloaded later but what about some ancillary classes & data held in them that's used by the controller that launched the view? Sample scenario in question: @interface MyCustomControll...

How can I maintain a global cache of objects? (or a NSMutableSet w/o retaining contents)

I have an iPhone app which deals with a subset of 25,000 places at any given time. I'd like to maintain a cache of places so that I know that if one part of my application updates a place, every other part that knows about that place sees the update. My nieve implementation is create an NSMutableSet to store references to the cached pl...

Do all class methods return an autoreleased object?

I'm re-reading the first few chapters of Cocoa Programming for Mac OS X and the author states that one of NSCalendarDate's class method returns an autoreleased object. I always assumed that all class methods returned an autoreleased object (since there's no alloc involved). Are there any class methods which you have to specifically reta...

Dynamic object creation and release

Hi, I have a class that instances some other classes. It's working to control their lifespan, or supposed to ;) A root class managing others which contain events and are subviews of the root view. I have a lot of graphics involved per view and need to clear things out before loading the next. Any idea how to unload the current subview...

Finding the event generator in obj c

Hi, I have a view with several subviews which in turn have several subviews. If I fire an event, say touches ended, in one of the bottom level views, how can I see what that event generating view was in the root view or second level view? Additionally any idea how to catch that event and then release the mid level view which would in t...

Memory Fragmentation Profiler

Are there any good memory fragmentation profilers? (linux gcc version would be nice). Valgrind cannot analyze this because it uses custom malloc/free functions. Thanks, Andrew ...

Named Pipe strategies with dynamic memory?

Hokay so I have an application where I need some IPC... I'm thinking named pipes are the way to go because they are so easy to use. Anyways, I have a question about how to handle dynamic memory using named pipes. Say I have a class such as this: class MyTestClass { public: MyTestClass() { _data = new int(4); } int GetData(...

Can I prevent invoking destructor before overloaded delete?

I'd like to use boost.pool. It's okay if you don't know about it. Basically, it has two main functions, malloc() and free(). I've overloaded new and delete for my custom defined class test. class test { public: test() { cout << "ctor" << endl; } ~test() { cout << "dtor" << endl; } vo...

Increasing the memory available to R processes

I would like to increase the amount of memory available to R. What are the methods for achieving this? ...

Arrays inside structs in C

Hello everyone. I´m struggling to understand this concept: I have a fixed size definition: (from http://msdn.microsoft.com/pt-br/library/aa931918.aspx) typedef struct _FlashRegion { REGION_TYPE regionType; DWORD dwStartPhysBlock; DWORD dwNumPhysBlocks; DWORD dwNumLogicalBlocks; DWORD dwSectorsPerBlock; DWORD dwBytesPerBloc...

Data initialized during 'init' methods after low memory condition handling

When an application comes back from low memory conditions (ie there was low memory, things were freed and the app is now back to normal use scenario), what happens to the state of objects that were initialized and set up via -(id)init method? When you receive low memory warnings, you persist all of the data and the viewDidUnload ...

Memory leak UIWebView when loading from file instead of URL?

I have a UIViewController that contains a UIWebView (OS 3.0). If I load it with file data, as soon as the 'Back Button' is hit and the view is dismissed, I'm seeing EXEC_BAD_ACCESS error with WebCore object releasing 'SharedBuffer' - (void)viewDidLoad { NSString *htmlFile = [[NSBundle mainBundle] pathForResource:fileName ofType:@"ht...

What is the scope of (nested) autorelease pools?

Hello, I'm creating an autorelease pool in a for loop (in method A). At each iteration of the loop, I'm calling another method (method B). Method B returns an autoreleased object to Method A. If I drain the pool within the for loop in Method A, will that release the objects sent from Method B? Thanks! ...

Differences between using realloc vs. free -> malloc functions

Why would one use realloc() function to resize an dynamically allocated array rather than using free() function before calling the malloc() function again (i.e. pros and cons, advantages vs. disadvantages, etc.)? It's for C programming, but I can't find the proper tag for it. Thanks in advance. ...

How to release an NSMutableDictionary Instance Variable properly, with nested dictionaries, in Objective-C?

I have an Objective-C class that looks something like: @interface myClass : NSObject { NSMutableDictionary *aDict; } Its setter method looks like: - (void) setADict: (NSMutableDictionary *) newDict { [aDict release]; [newDict retain]; aDict = newDict; } I've created an instance of the object, put data into aDict, an...

Why should you have to dispose() a java.awt.Window that goes out of scope?

One of the memory leaks I've discovered in our application is the java.awt.Window.allWindows private static field, which keeps track of every Window instantiated. We have dialog boxes that are created, used, and then forgotten, and the expectation was that these would go away and be garbage collected. This private field keeps them in s...

How is the Linux calculating MemFree

I am trying to understand my embedded linux memory usage. By using the top utility and the process file /proc/meminfo I can see how much virtual memory a process is using, and how much physical memory is available to the system. But it would seem for any given process the virtual memory can be very much higher than the used physical m...