memory-management

Dynamic Memory Reallocation using realloc

Hello All, I am learning C++. I am trying to learn this dynamic memory allocation. In the below code I am trying to allocate memory using malloc and realloc. int main (void) { char *g = (char*) malloc (sizeof(char) * 2); g = "ab"; g = (char*) realloc (g, sizeof(char) * 200); strcpy (g, "cdefg"); cout << g << endl; return 0...

Mathematica running out of memory

I'm trying to run the following program, which calculates roots of polynomials of degree up to d with coefficients only +1 or -1, and then store it into files. d = 20; n = 18000; f[z_, i_] := Sum[(2 Mod[Floor[(i - 1)/2^k], 2] - 1) z^(d - k), {k, 0, d}]; Here f[z,i] gives a polynomial in z with plus or minus signs counting in binary. ...

Do I need to release an returned NSError object?

There are many Cocoa methods that require an NSError object as a parameter to a method, but are really a means of returning an error object to the calling method if errors exist. Is this returned object retained? That is, in the calling object code (the method to which the error is returned), does there need to be some code like: NSEr...

How to push viewcontroller ( view controller ) ?

Hi, Memory management is a very important issue in iPhone. So I am asking a very general question. There are two ways to call a the viewController of another class. Way 1: AnotherClassViewController *viewController = [[[AnotherClassViewController alloc] initWithNibName:@"AnotherClassView" bundle:nil] autorelease]; [self.navigationCo...

Beginner help: when to call [obj release]?

I am programming my first iPhone app (which crashes with an EXC BAD ACCESS error). I've read a few other similar answers, but still don't have a clear picture of how to fix my code. Can someone help fix my memory management for the UITableViewCell *cell object in this snippet: - (UITableViewCell *)tableView:(UITableView *)tableView ce...

What happens if I try to access memory beyond a malloc()'d region?

I've allocated a chuck of memory with char* memoryChunk = malloc ( 80* sizeof(char) + 1); What is keeping me from writing into the memory location beyond 81 units? What can I do to prevent that? void testStage2(void) { char c_str1[20] = "hello"; char* ut_str1; char* ut_str2; printf("Starting stage 2 tests\n"); strcat(c_str1, " wor...

difference between drain, release,dealloc and retain in Objective-C/

Hi i want to know the difference between drain, release,dealloc and retain in Objective-C. ...

How to write a memory efficient Python program?

It's said that Python automatically manages memory. I'm confused because I have a Python program consistently uses more than 2GB of memory. It's a simple multi-thread binary data downloader and unpacker. def GetData(url): req = urllib2.Request(url) response = urllib2.urlopen(req) data = response.read() // data size is about...

Minimizing MVC memory consumption footprint

How can I minimize the footprint of a website built using MVC. My application currently runs at around 20mb, I'd like to reduce it if possible. Edit: I've switched hosts, problem solved. ...

NSString no 'assign', 'retain', or 'copy' attribute is specified

I'm declaring an NSString property in a class and objective-c is complaining that: NSString no 'assign', 'retain', or 'copy' attribute is specified It then casually lets me know that "assign is used instead". Can someone explain to me the difference between assign, retain and copy in terms of normal C memory management functions? ...

Problem with mmap/munmap - getting a bus error after the 783rd iteration?!?

Okay, here's the setup: I work in HPC, and we're preparing for the need to scale up to tens of thousands of nodes. To deal with this, I've implemented a local process that caches information on each node to reduce the amount of network traffic. It then exposes this information via shared-memory. The basic logic is that there is one well-...

Loop through NSMutableArray of custom objects in the most memory efficient way

What is the most memory efficient way to loop through an NSMutableArray of custom objects? I need to check a value in each object in the array and return how many of that type of object is in the array. ...

GUI for a GNU Debugger

Hi, am pretty excited with the GNU Debugger and a GUI called Insight as it has saved me A LOT OF time. Thus I am posting this question/answer for other newbies out there like me having problems with their C code looking for a visual way to see what's going on. I am working on Linux Mint (Ubuntu) btw. ...

Java: Garbage Collection

I'm having an out of memory error. I have a large range of inputs (2^40), that is too large to hold at once. Each input is a String[]. Instead, I thought I'd run my test program on each input, write the results to a file, then discard the input. The length of the longest input is 42, so that isn't an error causing the overflow. I don't...

Settings IBOutlets to nil in dealloc

In the section titled 'Memory Warnings' here http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmNibObjects.html, I don't follow why the IBOutlet is set to nil in the dealloc. If self.anOutlet = nil causes a crash as mentioned in the topic, why are they setting the ivar to nil? In general, ...

Heap fragmentation and windows memory manager

Hi, I'm having trouble with memory fragmentation in my program and not being able to allocate very large memory blocks after a while. I've read the related posts on this forum - mainly this one. And I still have some questions. I've been using a memory space profiler to get a picture of the memory. I wrote a 1 line program that conta...

Objective-C returning alloc'd memory in a function == bad?

This is on the iPhone. So what if I have a function like - (SomeObject*)buildObject; Do I need to pass in a variable that I have already alloc'd outside like - (void)assignObject(SomeObject** out); Or can I do - (SomeObject*)buildObject { return [[[SomeObject alloc] init] autorelease]; } and use it like SomeObject* obj = [[...

malloc results in segmentation fault after mprotect

I'm getting a segmentation fault the first time I call malloc() after I protect a memory region with mprotect(). This is a code sniplet that does the memory allocation the the protection: #define PAGESIZE 4096 void* paalloc(int size){ // Allocates and aligns memory int type_size = sizeof(double); void* p; p = ...

doubts regarding Memory management in .net

I'm ready about Memory management in C# from the book "Professional C#" The presence of the garbage collector means that you will usually not worry about objects that you no longer need; you will simply allow all references to those objects to go out of scope and allow the garbage collector to free memory as required. How...

Leaks showing extended memory usage when on iPhone vs Simulator

When, I run my application in the simulator using the Leaks instrument, it uses about 2.5mb of memory. When I run it on the iPhone, it takes forever to launch, slowly climbs to ~34mb of memory and then crashes. However, when I run it on the iPhone without Leaks, it launches quickly and runs fine. Why is this? ...