memory-management

Should I delete vector<string> ?

I've painfully learned during last few days a lot about programming in c++. I love it :) I know I should release memory - the golden "each malloc=free" or "each new=delete" rules exist now in my world, but I'm using them to rather simple objects. What about vector ? Wherever I can, I'm using vector.clear() but that clearly isn't enough, ...

Resolving ORA-4031 "unable to allocate x bytes of shared memory"

I need some pointers on how to diagnose and fix this problem. I don't know if this is a simple server setup problem or an application design problem (or both). Once or twice every few months this Oracle XE database reports ORA-4031 errors. It doesn't point to any particular part of the sga consistently. A recent example is: ORA-04031: ...

Memory Management and Python: how much do you need to know?

I know that a language like Python does garbage collection for you, but for any applications/optimizations or even security, is it important to understand how memory management works? I am very familiar, but I am going to start teaching a student soon, and I'm curious to know whether that's something we should go over. Note: this questi...

What kind of memory reclamation algorithm does MRI Ruby 1.8 use?

In other languages you have a number of possibilities usually for memory reclamation: Mark objects and then remove them Explicit retain and release Count references to objects Internal heap disposition How does Ruby work? ...

Understanding Objective-C's dynamic runtime

I'm getting my feet wet in Objective-C and Cocoa (I know, probably late, but hey I have to start somewhere) and I noticed that all objects are allocated out of the heap. Is there any reason why this is the standard in Objective-C? I tried looked everywhere (and yes, even on StackOverflow), but I couldn't find any explicit reason, except...

problem with the GNU "time" command to measure memory usage

Hello, I've been trying to use the time command /usr/bin/time to measure the peak memory consumption of a program on a linux system. Independently of what executable I experiment with, I get the correct answer for what regards running time, but memory usage figures are always 0. the typical output from time is something like: 8.68use...

Objective C memory management for anonymous objects

I'm working on learning Objective-C, and I'm trying to get a feel for the memory management. I'm fairly familiar with C memory management, but I'm trying to figure out how different ObjC is. Let's say I have a class called Complex that is used for holding complex numbers, which has a method -(Complex*)add:(Complex*)c; that adds the pass...

Lua garbage collection of Tables, nested Tables

[I've read the Lua manual, but it did not provide solid answers.] Let's say I have a Lua Table, acting as an indexed array: local myArray = {}; myArray[1] = "Foo"; myArray[2] = "Bar"; How do I best dispose of this Table? Do I just set myArray to nil? Or do I have to iterate through array and set each indexed element to nil? Simila...

Is memory management in different languages similar enough to transfer my knowledge?

I'm just starting to learn programming. And as of now, I know a tad bit of memory management in Objective-C. It wasn't easy learning it. So, just out of curiosity, is the memory management employed in major languages like C, C++, Java, etc., in any way similar to what I've learned? ...

Objective-c and memory leaks after a program terminates?

I am a new Objective-C programmer coming from a C#, VB.NET, Etc. These are all garbage collected languages and for the most part the worst thing you can do is abuse memory usage, because when your program shuts down the memory is reclaimed by the runtime. However, I am not clear about Objective-C. I get that for the most part its up to ...

NSAutoreleasePool carrying across methods?

I'm building an iPhone application where I detach some threads to do long-running work in the background so as not to hang the UI. I understand that threads need NSAutoreleasePool instances for memory management. What I'm not sure about is if the threaded method calls another method - does that method also need an NSAutoreleasePool? Exa...

Is it necessary to multiply by sizeof( char ) when manipulating memory?

When using malloc and doing similar memory manipulation can I rely on sizeof( char ) being always 1? For example I need to allocate memory for N elements of type char. Is multiplying by sizeof( char ) necessary: char* buffer = malloc( N * sizeof( char ) ); or can I rely on sizeof( char ) always being 1 and just skip the multiplicatio...

Java memory usage with native processes

What is the best way to tune a server application written in Java that uses a native C++ library? The environment is a 32-bit Windows machine with 4GB of RAM. The JDK is Sun 1.5.0_12. The Java process is given 1024MB of memory (-Xmx) at startup but I often see OutOfMemoryErrors due to lack of heap space. If the memory is increased to 1...

Can I set Java max heap size for running from a jar file?

I am launching a java jar file which often requires more than the default 64MB max heap size. A 256MB heap size is sufficient for this app though. Is there anyway to specify (in the manifest maybe?) to always use a 256MB max heap size when launching the jar? (More specific details below, if needed.) This is a command-line app that ...

When to make a object delete itself?

Callback* p = new Callback; func(p); If I want to delete the callback object, when and how to delete that? If it gets deleted early, then the callback may be failed. ...

How to find available memory in iPhone programmatically?

I'd like to know how to find programmatically available memory in iPhone from Objective-C? ...

Differences between dynamic memory and "ordinary" memory

What are some of the technical differences between memory that is allocated with the new operator and memory that is allocated via a simple variable declaration, such as int var? Does c++ have any form of automatic memory management? In particular, I have a couple questions. First, since with dynamic memory you have to declare a pointer...

How do I handle memory management in this situation?

I have two classes, a class that handles db connectivity and an entity class. The db class has an instance method called GetEntityByID:(int)entity_id. This method does a simple select statement, and creates an Entity class instance using an init method. This works fine, however whoever calls GetEntityByID must remember to release it...

Is there anything that makes memory management easier for iPhone/iPod Touch application programming?

I've only used Java and Ruby for so long that I'm really not enjoying keeping track of my own memory again. It's not that I can't do it, I can. I just don't want to. Any special tricks, libraries, or anything else you've learned for dealing with memory in iApps, lay it on me here. ...

When HeapCreate function is used or in what cases do you need a number of heaps?

Windows API has a set of function for heap creation and handling: HeapCreate, HeapAlloc, HeapDestroy and etc. I wonder what is the use for another heap in a program? From fragmentation point of view, you will get external fragmentation where memory is not reused among heaps. So even if low-fragmentation heaps are used, stil there is a f...