memory-management

Disadvantages of calling realloc in a loop

雨燕双飞 提交于 2019-12-24 04:02:32
问题 I'm trying to implement some math algorithms in C on Windows 7, and I need to repeatedly increase size of my array. Sometimes it fails because realloc can't allocate memory. But if I allocate a lot of memory at once in the beginning it works fine. Is it a problem with the memory manager? Can anyone explain me this please? 回答1: When you allocate/deallocate memory many times, it may create fragmentation in the memory and you may not get big contiguous chunk of the memory. When you do a realloc,

Garbage Collector, call & callvirt and Debug/Release code mode execution differences

独自空忆成欢 提交于 2019-12-24 03:52:07
问题 I have a class: public class SomeClass { public int I; public SomeClass(int input) { I = input; Console.WriteLine("I = {0}", I); } ~SomeClass() { Console.WriteLine("deleted"); } public void Foo() { Thread.Sleep(1000); Console.WriteLine("Foo"); } } and this program: class Program { static void Main(string[] args) { new Thread(() => { Thread.Sleep(100); GC.Collect(); }) { IsBackground = true }.Start(); new SomeClass(10).Foo(); // The same as upper code // var t = new SomeClass(10); // t.Foo();

“[CALayer release]: message sent to deallocated instance” when dismissing modal view controller

大城市里の小女人 提交于 2019-12-24 03:50:28
问题 I've been struggling with this for last few days and I cannot find any solution, so I ask you for advice. I have two UIViewControllers: NewPostUIViewController and SettingsUIViewController. In the second one I have a field: id<SettingsUIViewControllerDelegate> delegate and the first one implements protocol SettingsUIViewControllerDelegate When a button is pressed the following code is executed in NewPostUIViewController: SettingsUIViewController *settingsUIViewController = [

Redshift Querying: error xx000 disk full redshift

拟墨画扇 提交于 2019-12-24 03:20:35
问题 I executed the below query select employee_name, max(employee_dept) as dept from employeeDB where employee_name is not null and employee_name != '' group by employee_name order by employee_name asc limit 1000 and received the error ERROR: XX000: Disk Full . upon investigation by executing the below query i found that i have 941 GB free space and 5000 GB used space. select sum(capacity)/1024 as capacity_gbytes, sum(used)/1024 as used_gbytes, (sum(capacity) - sum(used))/1024 as free_gbytes from

Hotspot JVM array allocation

时光总嘲笑我的痴心妄想 提交于 2019-12-24 03:09:22
问题 I've been searching for days for proper documentation on Hotspot JVM, with regards to the way arrays are allocated (an). By this, I mean what's the actual structure of the array, when allocated in memory, is it made out of contiguous blocks or is it a tree like structure. I need the structure to come up with a formula of the size (a formula which takes size of object and array length as inputs). From the tests I've run and from what code I could understand, I've come up with arrays being

C++ conditional storage allocation for object caused by scope

我怕爱的太早我们不能终老 提交于 2019-12-24 03:05:41
问题 Currently I'm reading Think in C++ . I'm confused about the conditional storage allocation for an object . As the code below, the goto and switch generate warning or an error . But if-else works fine, which is conditionally passed through during execution. So why there is no warning or error for if-else ? /* crosses initializaion error */ #include <iostream> using namespace std; class X { public: X(); }; X::X() {} void f(int i) { if (i > 2) { X x1; } else { X x2; // why conditionally executed

What's the status of the MADV_USERFAULT flag in madvise()?

一世执手 提交于 2019-12-24 03:01:59
问题 There have been some discussions to use a new flag in madvise() to tell the kernel not to handle page faults in certain memory ranges: lwn.net-1, lwn.net-2 As far as I am able to see, this flag hasn't found its way to the kernel source. What's the current status of this work? 回答1: The community never went forward with MADV_USERFAULT. Instead, a more robust solution called userfaultfd has made its way into the kernel. https://www.kernel.org/doc/Documentation/vm/userfaultfd.txt 来源: https:/

How much memory is my iphone app using (from Simulator)

[亡魂溺海] 提交于 2019-12-24 03:00:37
问题 I know this has something to do with Instruments, but well it's kind of confusing and searching for Instruments on Google doesn't help much. I'd like to know how well my app runs, like how much memory it uses. I just don't know where to find something like: "As close as we can tell from the simulator you'll app will currently be using xx MBs of RAM on a real iphone device." I need help on how to get this information. 回答1: You shouldn't test your memory usage in the simulator for a number of

why [self.property release] will cause the static analyzer to show an “incorrect decrement of the reference count” error? [duplicate]

不问归期 提交于 2019-12-24 02:33:45
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Incorrect decrement of the reference count of an object that is not owned at this point by the caller Why shouldn't I use the getter to release a property in objective-c? So, I get that using [self.myProperty release] is discouraged (Apple itself recommends not to). Although it appears to me that it COULD lead to problems in some cases, not all cases. Is this correct? More importantly: I don't get why using a

Memory Leak with SubstringWithRange NSString

血红的双手。 提交于 2019-12-24 02:18:13
问题 Running my program through the Leaks tool in X-Code, it points to this function as the main cause of my memory leaks. + (NSMutableArray *) getColumns:(NSString *) deviceHtml { NSMutableArray *ret = [[[NSMutableArray alloc] init] autorelease]; NSRegularExpression *m = [[NSRegularExpression alloc] initWithPattern:@"<td[\\w\\W\\d\\s</>]*?>[\\w\\W\\d\\s]+?</td>" options:NSRegularExpressionCaseInsensitive error:nil]; NSArray *results = [m matchesInString:deviceHtml options:NSMatchingCompleted