Archived

This topic is now archived and is closed to further replies.

Code to make the biggest and baddest memory leak possible?

This topic is 5827 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
    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

Share this post


Link to post
Share on other sites
#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...

Share this post


Link to post
Share on other sites
c:\> copy con eat.bat
type eat.bat>>eat.bat
<F6>
c:\> eat<enter>

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

Share this post


Link to post
Share on other sites