Efficiently counting the number of lines of a text file. (200mb+)

This will use less memory, since it doesn’t load the whole file into memory: $file=”largefile.txt”; $linecount = 0; $handle = fopen($file, “r”); while(!feof($handle)){ $line = fgets($handle); $linecount++; } fclose($handle); echo $linecount; fgets loads a single line into memory (if the second argument $length is omitted it will keep reading from the stream until it reaches … Read more

docker for mac memory usage in com.docker.hyperkit

As @GabLeRoux has shared in a comment, the “Real Memory” usage is much lower than what you see in the “Memory” column in Activity Monitor. This document thoroughly explains memory usage on Mac OS with Docker Desktop and information is excerpted from there. To see the “Real Memory” used by Docker, right-click the column names … Read more

Meaning of Leaky Abstraction?

Here’s a meatspace example: Automobiles have abstractions for drivers. In its purest form, there’s a steering wheel, accelerator and brake. This abstraction hides a lot of detail about what’s under the hood: engine, cams, timing belt, spark plugs, radiator, etc. The neat thing about this abstraction is that we can replace parts of the implementation … Read more

Do I need to remove event listeners before removing elements?

Just to update the info here. I’ve been testing various browsers, specifically for memory leaks for circularly dependent event listeners on iframe onload events. The code used (jsfiddle interferes with memory testing, so use your own server to test this): <div> <label> <input id=”eventListenerCheckbox” type=”checkbox” /> Clear event listener when removing iframe </label> <div> <button … Read more

How far can memory leaks go?

No. Operating systems free all resources held by processes when they exit. This applies to all resources the operating system maintains: memory, open files, network connections, window handles… That said, if the program is running on an embedded system without an operating system, or with a very simple or buggy operating system, the memory might … Read more

error opening HPROF file: IOException: Unknown HPROF Version

The hprof file you get from Android has android specific format. You should convert hprof file take from Android OS into standard hprof format. For this you can use hprof-conv tool that is located at AndroidSDK/tools/hprof-conv. For example: hprof-conv android.hprof mat.hprof And then open mat.hprof in Memory Analyzer. EDIT: hprof-conv might be located under AndroidSDK/platform-tools/ … Read more