memory-management

Does deleting a pointer delete the memory it's pointing too?

 ̄綄美尐妖づ 提交于 2020-01-01 04:44:28
问题 If I have a pointer like so: int *test = new int; And I create another pointer that points to test like so: int *test2 = test; Then I delete test2 : delete test2; Does that mean that it will delete the memory of test as well, or would I have to call delete test also? 回答1: Yes, the memory will be deleted freed as both pointers point to the same memory. Furthermore, test will now be a dangling pointer (as will test2 ) and dereferencing it will result in undefined behaviour . 回答2: You never

Explain this memory consumption pattern in Amazon RDS/Mysql?

点点圈 提交于 2020-01-01 04:28:04
问题 Folks, Can someone explain this memory consumption pattern on Amazon RDS running Mysql? In this graph, I upgraded to a db.m2.2xlarge, with 34GB of available memory, at 03:30. You can see the switchover very clearly. As clients start connecting and hitting that instance, the Freeable memory drops steeply to 5GB, where it is now hovering. On my previous upgrade between DB instance sizes, I saw the same pattern, until the freeable memory dropped to just under 1GB and hovered there indefinitely.

Any Java caches that can limit memory usage of in-memory cache, not just instance count?

本秂侑毒 提交于 2020-01-01 04:24:11
问题 I am looking for a simple in-memory (and in-process) cache for short-term caching of query data (but short-term meaning beyond request/response, i.e. session boundary). EhCache would probably work, but it looks as if it might not offer one thing that I need: limits not on number of objects cached, but (approximate) limit on amount of memory consumed by cached data. I understand that it is hard to figure out exact memory usage for given object without serialization (which I want to avoid in

How to reduce Netbeans' memory usage?

[亡魂溺海] 提交于 2020-01-01 04:05:08
问题 When using netbeans to edit a PHP project, the IDE can (over time) use 400+ MB of memory. Is there any way to turn off certain features or other tricks to reduce its memory usage? 回答1: You can set the min & max memory limits via the netbeans.conf file. Please, refer to the next faqs: http://wiki.netbeans.org/FaqSlowNetBeans http://wiki.netbeans.org/FaqNetBeansAndOOME 回答2: Haven't found any way to reduce either Eclipse and Netbeans. The problem is that javas JVM is using significant amout of

Memory allocation for array of structure pointers

喜欢而已 提交于 2020-01-01 03:59:09
问题 I'm trying to build a memory allocator in C. The user starts by saying how much memory he wants to use, and the smallest block size of memory that can be made available. So, for example, let's say the user requests 1024B with the smallest block size of 8B. That means the possible block sizes would be 1024, 512, 256, 128, 64, 32, 16, and 8. To keep track of the free blocks of memory, I have an array of pointers to structures. These structures are called Header, and the array is called FreeList

std::string implementation in GCC and its memory overhead for short strings

此生再无相见时 提交于 2020-01-01 03:57:07
问题 I am currently working on an application for a low-memory platform that requires an std::set of many short strings (>100,000 strings of 4-16 characters each). I recently transitioned this set from std::string to const char * to save memory and I was wondering whether I was really avoiding all that much overhead per string. I tried using the following: std::string sizeTest = "testString"; std::cout << sizeof(sizeTest) << " bytes"; But it just gave me an output of 4 bytes, indicating that the

Finding Memory Usage in Java

百般思念 提交于 2020-01-01 03:30:18
问题 Following is the scenario i need to solve. I have struck with two solutions. I need to maintain a cache of data fetched from database to be shown on a Swing GUI. Whenever my JVM memory exceeds 70% of its allocated memory, i need to warn user regarding excessive usage. And once JVM memory usage exceeds 80%, then i have to halt all the database querying and clean up the existing cache fetched as part of the user operations and notifying the user. During cleanup process, i will manually handle

String manipulation without memory leaks?

大憨熊 提交于 2020-01-01 03:26:07
问题 I'd like to do a series of string substitutions to removed xml-escaped chars such as '&' . 1) Is there an existing UIKit function that can do this? 2) If not, what's the best way to do it without leaking memory? Here's the idea: -(NSString*) unescape:(NSString*)string { string = [string stringByReplacingOccurrencesOfString:@"&apos;" withString:@"'"]; string = [string stringByReplacingOccurrencesOfString:@"&" withString:@"&"]; string = [string stringByReplacingOccurrencesOfString:@"""

current->mm gives NULL in linux kernel

寵の児 提交于 2020-01-01 03:16:28
问题 I would like to walk the page table, so I have accessed the current->mm, but it gives NULL value. I'm working on linux kernel 3.9 and I don't understand how could current->mm is zero. Is there something I miss here? 回答1: It means you are in a kernel thread. In Linux, kernel threads have no mm struct. A kernel thread borrows the mm from the previous user thread and records it in active_mm. So you should use active_mm instead . More details: in /kernel/sched/core.c you can find the following

Lock-free memory reclamation with hazard pointers

走远了吗. 提交于 2020-01-01 02:30:29
问题 Hazard pointers are a technique for safely reclaiming memory in lock-free code without garbage-collection. The idea is that before accessing an object that can be deleted concurrently, a thread sets its hazard pointer to point to that object. A thread that wants to delete an object will first check whether any hazard pointers are set to point to that object. If so, deletion will be postponed, so that the accessing thread does not end up reading deleted data. Now, imagine our deleting thread