-3
\$\begingroup\$

Your task is to write a program that:

  • Runs indefinitely
  • Produces no output
  • Consumes an unbounded amount of memory

Specifications

  • You must list the implementation used for your program. This is relevant because some implementations might preform optimizations while others do not. For example, the LISP code (defun f () (f)) (f) may or may not consume infinite memory depending on whether the implementation optimizes tail recursion.
  • Obviously, your program may terminate from running out of memory.

Examples

BF:

+[>+]

Python:

l = []
while True:
    l.append(1)

JavaScript:

l = [];
while (true)
    l.push(1);

C (I'm not sure if this works):

#include <stdio.h>
int main() {
    while (1)
        malloc(1);
}

This is , so the shortest valid solution (in bytes) wins.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ A dup of codegolf.stackexchange.com/questions/101709/… \$\endgroup\$
    – zeppelin
    Commented Feb 15, 2017 at 7:17
  • 1
    \$\begingroup\$ Depending on how strictly you interpret things: if a C compiler can prove that code has no effect, it can replace it with anything else that also has no effect. So given an arbitrarily smart compiler, it might not be possible to write an infinite C program with no effect. In practice this is hampered by the fact that none of our compilers can solve the halting problem. Also, malloc is in stdlib.h, not stdio.h. \$\endgroup\$
    – ephemient
    Commented Feb 15, 2017 at 7:21
  • \$\begingroup\$ @ephemient That's why I forced you to specify the implementation. Also, some compilers will already include <stdlib.h> by default. \$\endgroup\$ Commented Feb 16, 2017 at 1:00
  • \$\begingroup\$ Some compilers will happen to pull in stdlib.h transitively via stdio.h. That doesn't mean they include stdlib.h by default. \$\endgroup\$
    – ephemient
    Commented Feb 16, 2017 at 2:13

8 Answers 8

1
\$\begingroup\$

Jelly, 2 bytes

‘ß

Increments and calls itself recursively. As the integer gets bigger, more memory is required to store it.

You can Try it online!, but it's not much to look at.

\$\endgroup\$
2
  • \$\begingroup\$ Wouldn't this cause stack overflow before your computer runs out of memory? \$\endgroup\$
    – Pavel
    Commented Feb 15, 2017 at 7:00
  • \$\begingroup\$ No, Jelly has tail call optimization. This is just a fancy while loop. \$\endgroup\$
    – Dennis
    Commented Feb 15, 2017 at 7:01
0
\$\begingroup\$

Python 3, 16 bytes

i=9
while i:i*=9

As ints in Python3 are only limited by the memory, this will run until there is no more memory available.

\$\endgroup\$
0
\$\begingroup\$

Befunge-98, 1 byte

'

Fills the stack with strings containing '

\$\endgroup\$
0
\$\begingroup\$

Java (OpenJDK 9), 75 bytes

interface G{static void main(String[]a){a=new String[1];for(;;)a[0]+=' ';}}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Bash, 17 bytes

for((;;)){ a+=a;}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Brain-Flak, 8 bytes

(()){()}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Since the {...} monad keeps track of the value of each run, you could simply do (()){[]} or (()){()} instead. \$\endgroup\$
    – DJMcMayhem
    Commented Feb 15, 2017 at 8:39
0
\$\begingroup\$

Vim, 13 bytes

qqaa<esc>"Ax@qq@q

This defines a macro, q that appends the letter a to the register A and then calls itself. This results in an infinite loop of making register A bigger and bigger, only limited by memory.

\$\endgroup\$
1
  • \$\begingroup\$ It looks to me like you're missing an <esc> in the macro. This will just output a"Ax@qq@q and exit. \$\endgroup\$
    – DJMcMayhem
    Commented Feb 15, 2017 at 23:39
0
\$\begingroup\$

Ruby, 15 bytes

i=[];loop{i<<0}
\$\endgroup\$

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