memory-management

Deleting object with private destructor

a 夏天 提交于 2019-12-30 06:12:54
问题 How is that possible that it is allowed to delete object with private destructor in the following code? I've reduced real program to the following sample, but it still compiles and works. class SomeClass; int main(int argc, char *argv[]) { SomeClass* boo = 0; // in real program it will be valid pointer delete boo; // how it can work? return -1; } class SomeClass { private: ~SomeClass() {}; // ! private destructor ! }; 回答1: You are trying to delete object of incomplete class type. C++ Standard

What's the unit of `ru_maxrss` on Linux?

自古美人都是妖i 提交于 2019-12-30 05:59:37
问题 This is from man getrusage struct rusage { struct timeval ru_utime; /* user time used */ struct timeval ru_stime; /* system time used */ long ru_maxrss; /* maximum resident set size */ long ru_ixrss; /* integral shared memory size */ long ru_idrss; /* integral unshared data size */ long ru_isrss; /* integral unshared stack size */ long ru_minflt; /* page reclaims */ long ru_majflt; /* page faults */ long ru_nswap; /* swaps */ long ru_inblock; /* block input operations */ long ru_oublock; /*

When is an autoreleased object actually released?

ぃ、小莉子 提交于 2019-12-30 05:57:11
问题 I am new in objective-c and I am trying to understand memory management to get it right. After reading the excellent Memory Management Programming Guide for Cocoa by apple my only concern is when actually an autoreleased object is released in an iphone/ipod application. My understanding is at the end of a run loop . But what defines a run loop in the application? So I was wondering whether the following piece of code is right. Assume an object @implementation Test - (NSString *) functionA {

When is an autoreleased object actually released?

耗尽温柔 提交于 2019-12-30 05:56:12
问题 I am new in objective-c and I am trying to understand memory management to get it right. After reading the excellent Memory Management Programming Guide for Cocoa by apple my only concern is when actually an autoreleased object is released in an iphone/ipod application. My understanding is at the end of a run loop . But what defines a run loop in the application? So I was wondering whether the following piece of code is right. Assume an object @implementation Test - (NSString *) functionA {

How do I free memory obtained by sbrk()?

只愿长相守 提交于 2019-12-30 05:45:08
问题 I have a custom allocator function which uses sbrk() to obtain memory. How do I release this memory when it's no longer needed? Is there a function equivalent to free() for malloc() ? or do I have to use brk() to set the end of the data segment ? 回答1: You need to use brk or sbrk again to shrink. In the end the only way you have to modify the amount of memory(apart from mmap like syscalls), is to increase or decrease the heap, so you move it up with sbrk or brk and you move it down with brk or

ARC: “Pointer to non-const type 'id' with no explicit ownership”

血红的双手。 提交于 2019-12-30 05:44:27
问题 i am upgrading an iOS 4 project to use it with ARC with the sdk5. So i want to use the automatic refactor method for converting the code to use ARC. Unfortunately it does´t work. I get a lots of errors.. for(id* child in childObjectArray){ [child removeParentGroupReferences]; } That gives me the following error output: Pointer to non-const type 'id' with no explicit ownership Any help about that? What do i have to change? Thanks for any help.. 回答1: Change id* to id . id is already defined as

How to profile memory usage of a C program

╄→гoц情女王★ 提交于 2019-12-30 04:48:11
问题 I need to figure out which part of a linux program that I am running, is taking how much (either percentage, or absolute) memory. I need to create a profile of multiple such programs, so that I can identify some of the bigger consumers of memory in my code, and see if I can optimize them to use less. I need it on MIPS platform, and unfortunately, Valgrind doesn't work on MIPS. Any help/pointers would be greatly appreciated. 回答1: You could wrap all your calls to free and malloc with your own

Is there a way I get the size of a PHP variable in bytes?

假如想象 提交于 2019-12-30 04:01:08
问题 I currently have a PHP CLI script using Zend Framework extensively which seems to be using a ever larger amount of memory as it runs. It loops through a large set of models retrieved from a database in batches of 1000. Calls to memory_get_usage() show that the memory usage of the script is always increasing. This is despite making sure that I'm unsetting the model after every iteration and actually using array_shift() to reduce the size of the array of models on every iteration. My question

Return dynamically allocated memory from C++ to C

两盒软妹~` 提交于 2019-12-30 03:35:27
问题 I have a dll that must be useable from C etc, so I cant use string objects etc as a normal would, but I'm not sure on how to do this safely.. const char *GetString() { std::stringstream ss; ss << "The random number is: " << rand(); return ss.str().c_str(); } could the c string be destroyed when ss falls off the stack? I'm assuming so... Another option may be to create a new string on the heap, but what is going to deallocate that? const char *GetString() { std::stringstream ss; ss << "The

growing python process memory over time

浪尽此生 提交于 2019-12-30 03:17:47
问题 My python code process memory increases dynamically as it stores dynamic data in list, dictionary and tuples wherever necessary. Though all those dynamic data is cleared physically in their variables after then, the memory is not shooting down. Hence i felt like there is a memory leak and i used gc.collect() method to collect all the unfreed memory. But i could not make the memory to minimum when there is no data in the variables. 回答1: It's very hard, in general, for a process to "give memory