Code to make the biggest and baddest memory leak possible?

Started by
8 comments, last by amemorex 22 years, 3 months ago
Anyone have any code that can create huge memory leaks at ultra fast speeds? I''m trying to test out a memory manager I recently purchased, and want to run some code that will generate some huge leaks.
Advertisement
Assuming you use C++, just create a simple class that allocates a random amound of memory using malloc() in it''s constructor.

Creata a few thousand instances in a loop, then destroy ''em.
  #include <malloc.h>int main(){  while (1)    char *c=(char *)malloc(1048576);}  


-----------------------
0wn 0wn 0wn your goat
gently down the pw33n
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
This should work ( haven''t tested it ):

  void CreateMemoryLeak( int size_to_allocate ){    char *dummy = new char[size_to_allocate];}  


You could then just do something like:

CreateMemoryLeak( 0xffffffff ) to create a 4Gb memory leak, although that would quite possibly crash your system.

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
    void CreateNastierMemLeak(long long size){    long long *evil = (long long*)malloc(sizeof(long long) * size);}    


just to make it more evil, i used malloc

Edited by - barazor on January 1, 2002 4:06:39 PM
I see there''s a function called "HeapLock"... I wonder if this would screw the system over:

while(1) HeapLock(HeapCreate(0, 1024*1024, 0));


#include

int main() {
while (1)
fork();
}

If you were all stylin unix style.

If you want to test a memory manager, best thing would be to use annoying size memory blocks like

1025 bytes (instead of 1024) or
64536 bytes.. or ... the worst for a memory manager would be to keep allocating 1 byte at a time...
~~~~~~~~~~~~~~~~~~~~~~~~~~~AIM: GelfTheElf
From the DOS prompt:

  int main(){   system(win.com);   return(0);}  
He doesn''t want to kill his machine man!
c:\> copy con eat.bat
type eat.bat>>eat.bat
&ltF6>
c:\> eat&ltenter>

You could get really devious and launch processes recursively all at REAL_TIME priority.

Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

"What I see is a system that _could do anything - but currently does nothing !" - Anonymous CEO
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement