Is “Out Of Memory” A Recoverable Error?

It really depends on what you’re building. It’s not entirely unreasonable for a webserver to fail one request/response pair but then keep on going for further requests. You’d have to be sure that the single failure didn’t have detrimental effects on the global state, however – that would be the tricky bit. Given that a … Read more

What is the difference between a __weak and a __block reference?

From the docs about __block __block variables live in storage that is shared between the lexical scope of the variable and all blocks and block copies declared or created within the variable’s lexical scope. Thus, the storage will survive the destruction of the stack frame if any copies of the blocks declared within the frame … Read more

memory_get_peak_usage() with “real usage”

Ok, lets test this using a simple script: ini_set(‘memory_limit’, ‘1M’); $x = ”; while(true) { echo “not real: “.(memory_get_peak_usage(false)/1024/1024).” MiB\n”; echo “real: “.(memory_get_peak_usage(true)/1024/1024).” MiB\n\n”; $x .= str_repeat(‘ ‘, 1024*25); //store 25kb more to string } Output: not real: 0.73469543457031 MiB real: 0.75 MiB not real: 0.75910949707031 MiB real: 1 MiB … not real: 0.95442199707031 MiB … Read more

How can I create a reference cycle using dispatchQueues?

You say: From what I understand the setup here is: self —> queue self <— block The queue is merely a shell/wrapper for the block. Which is why even if I nil the queue, the block will continue its execution. They’re independent. The fact that self happens to have a strong reference to the queue … Read more

Memory allocation and deallocation across dll boundaries

Ironically enough, the Adobe Source Libraries has a adobe::capture_allocator class that was written specifically with this kind of DLL safety in mind. The way it works is to capture the local new and delete at this point it is instantiated, and to carry them both around for the lifetime of the object. (See adobe::new_delete_t for … Read more

How to calculate private working set (memory)?

This is a highly variable number, you cannot calculate it. The Windows memory manager constantly swaps pages in and out of RAM. TaskMgr.exe gets it from a performance counter. You can get the same number like this: using System; using System.Diagnostics; class Program { static void Main(string[] args) { string prcName = Process.GetCurrentProcess().ProcessName; var counter … Read more

What is the cost of using autorelease in Cocoa?

There are two costs: (Assuming you have an option to avoid autoreleased objects.) You effectively unnecessarily extend the lifetime of your objects. This can mean that your memory footprint grows — unnecessarily. On a constrained platform, this can mean that your application is terminated if it exceeds a limit. Even if you don’t exceed a … Read more