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\$

closed as off-topic by Alex A. Feb 5 '16 at 23:05

  • This question does not appear to be about programming puzzles or code golf within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

locked by Alex A. Feb 5 '16 at 23:05

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. See the help center for guidance on writing a good question.

Read more about locked posts here.

  • 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 '14 at 22:25
  • 54
    \$\begingroup\$ Isn't this just while(1)malloc(999);? \$\endgroup\$ – Doorknob Mar 18 '14 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\$ – acbabis Mar 18 '14 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\$ – Braden Best Mar 19 '14 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 '14 at 8:15

31 Answers 31

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\$

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