54
votes
\$\begingroup\$

Your task is to create a memory leak. This is a program that uses loads of memory, until the computer runs out and has to do some swapping to save itself from running out. The only way that the memory can be released is by killing the program in the task manager or using a command line kill such as taskkill /im yourprogram /f (in Windows) or even restarting the computer. Merely closing the app should not prevent it from continuing to hog memory.

Rules:

  1. Fork bombs of any sort are banned. That means that infamous Bash line :(){ :|:&};: is banned!

  2. The application must be single-threaded only. This implies the fork bomb rule.

  3. The program must not run other programs. This means that you can't just do something like run(memoryfiller.exe). The only exception to this is programs that are bundled with your OS or language, that are not primarily designed to consume memory (i.e. they have another purpose). This means that things like cat and ln -s are permitted.

  4. You can take up as much memory as you like. The more the better.

  5. Code must be explained fully.

Good luck. This is a popularity contest so the code with the most votes after 10 days from the asking date wins!

\$\endgroup\$
18
  • 8
    \$\begingroup\$ "Closing it should still make it hog memory" - if a program is a shell executable (like most of windows versions of scripting language interpreters are), closing its window will kill the program. \$\endgroup\$
    – mniip
    Mar 18, 2014 at 22:25
  • 54
    \$\begingroup\$ Isn't this just while(1)malloc(999);? \$\endgroup\$
    – Doorknob
    Mar 18, 2014 at 22:32
  • 10
    \$\begingroup\$ I'm not sure if "Closing it should still make it hog memory" is compatible with "The application must be single threaded only." If no thread has a chunk of memory, the OS can take it back, right? \$\endgroup\$
    – aebabis
    Mar 18, 2014 at 22:34
  • 51
    \$\begingroup\$ Just run firefox 26 with a few tabs open running flash for a half hour. It'll bring your computer to its knees. \$\endgroup\$ Mar 19, 2014 at 4:01
  • 1
    \$\begingroup\$ @mniip. That's the whole point of the challenge. To make a difficult challenge. And doorknob. I wanted something different! ;) \$\endgroup\$
    – George
    Mar 19, 2014 at 8:15

31 Answers 31

1
2
0
votes
\$\begingroup\$

perl, 11 chars

I know this isn't code golf, but here's my code-golfy answer, which simply grows the stack indefinitely (you can do that in perl, unlike most C implementations).

sub l{l()}l

Be sure to set ulimit -v before running, it eats a gigabyte per second.

\$\endgroup\$
1
2

Not the answer you're looking for? Browse other questions tagged or ask your own question.