memory-management
How to measure memory usage from inside a C++ program?
Yes – use POSIX getrusage. From the Linux man page: Synopsis #include <sys/time.h> #include <sys/resource.h> int getrusage(int who, struct rusage *usage); Description getrusage() returns current resource usages, for a who of either RUSAGE_SELF or RUSAGE_CHILDREN. The former asks for resources used by the current process, the latter for resources used by those of its children …
Using realloc to shrink the allocated memory
No, you won’t have a memory leak. realloc will simply mark the rest “available” for future malloc operations. But you still have to free myPointer later on. As an aside, if you use 0 as the size in realloc, it will have the same effect as free on some implementations. As Steve Jessop and R.. …
Difference between logical addresses, and physical addresses?
This answer is by no means exhaustive but it may explain it enough to make things click. In virtual memory systems, there is a disconnect between logical and physical addresses. An application can be given a virtual address space of (let’s say) 4G. This is its usable memory and it’s free to use it as …
Are instance variables set to nil by default in Objective-C?
Instance variables are initialized to 0 before your initializer runs..
Circular References Cause Memory Leak?
Great question! No, Both forms will be (can be) GC’d because the GC does not directly look for references in other references. It only looks for what are called “Root” references … This includes reference variables on the stack, (Variable is on the stack, actual object is of course on the heap), references variables in …
Do class methods increase the size of the class instances?
Only instance data increases the size of instances of a class (in all implementations that I know of), except that if you add virtual functions or inherit from a class with virtual functions then you take a one-time hit for a v-table pointer. Also, as someone else correctly mentions the minimum size of a class …
How to get the amount of memory used by an application [duplicate]
You can use the following function (The true parameter tells the GC to perform a collection first): long memory = GC.GetTotalMemory(true);
why is the destructor call after the std::move necessary?
Moving from an object just means that the moved-from object might donate its guts to live on in another live object shortly before it is [probably] going to die. Note, however, that just because an object donated its guts that the object isn’t dead! In fact, it may be revived by another donating object and …