Valhalla Legends Archive

Programming => General Programming => Topic started by: 111787 on May 18, 2005, 08:26 PM

Title: Memory Leak
Post by: 111787 on May 18, 2005, 08:26 PM
What exactly does it mean, besides the obvious? What exactly causes a Memory Leak?
Title: Re: Memory Leak
Post by: Kp on May 18, 2005, 08:29 PM
An ill-maintained memory faucet?
Title: Re: Memory Leak
Post by: 111787 on May 18, 2005, 08:30 PM
it makes perfect sense now, any serious answers?
Title: Re: Memory Leak
Post by: Hdx on May 18, 2005, 08:51 PM
Something that keeps eating away at the end-user's ram. Just blocks of memory sitting there used up, with no purpose. Like loading data from a file and having the thing jsut sit in momory (prime example, during bnet's hashing functions, you have to load the files DWORDS at a time, they add up.)
~-~(HDX)~-~
Title: Re: Memory Leak
Post by: K on May 18, 2005, 10:17 PM
Memory that is allocated that isn't deallocated.  For example in C/C++ allocating data using malloc/new and forgetting to free/delete[] it.  The memory is still marked as used by the system's memory manager, so it can't be used to fill another memory allocation request.
Title: Re: Memory Leak
Post by: Adron on May 19, 2005, 11:40 AM
A Memory Leak can be described in many ways.

A. It could be any block of memory that remains allocated when the program finishes execution and has to be automatically freed by the OS.

B. It could be any allocated memory block to which there is no reference or pointer in the program.

C. It could be a program doing something, and after it's done that has a higher memory use than before.

D. It could be C, with the additional requirement that the memory use continues to grow without an upper bound as the program executes.


For A:

main()
{
    char *a = new char[100];
}


For B:

main()
{
    char *a = new char[100];
    a = 0;
}


For C:

func(int n)
{
   static int *ar[100];
   if(!ar[n]) ar[n] = new int;
}
main()
{
    func(1);
    func(2);
}


For D:

func(int n)
{
   struct item {
       int n;
       struct item *next;
   };
   static item *head;
   item *p;
   p = new item;
   p->n = n;
   p->next = head;
   head = p;
}
main()
{
    func(1);
    func(2);
}

Title: Re: Memory Leak
Post by: 111787 on May 19, 2005, 02:03 PM
good thing Kp explained so well that I don't have to figure out what the rest of you guys are saying with your crazy big words like allocated memory block.
Title: Re: Memory Leak
Post by: Kp on May 19, 2005, 04:29 PM
Quote from: 111787 on May 19, 2005, 02:03 PM
good thing Kp explained so well that I don't have to figure out what the rest of you guys are saying with your crazy big words like allocated memory block.

If you don't understand the idea of an allocated memory block, you really have no business managing memory.  If you aren't managing memory, you can't affect any potential leaks, which makes explaining them to you pointless.
Title: Re: Memory Leak
Post by: Maddox on May 19, 2005, 05:03 PM
Quote from: Kp on May 19, 2005, 04:29 PM
Quote from: 111787 on May 19, 2005, 02:03 PM
good thing Kp explained so well that I don't have to figure out what the rest of you guys are saying with your crazy big words like allocated memory block.

If you don't understand the idea of an allocated memory block, you really have no business managing memory.  If you aren't managing memory, you can't affect any potential leaks, which makes explaining them to you pointless.

You are not a very good detector of sarcasm.  :P
Title: Re: Memory Leak
Post by: Kp on May 19, 2005, 05:57 PM
Quote from: Maddox on May 19, 2005, 05:03 PMYou are not a very good detector of sarcasm.  :P

Based on the original poster's comments, it seemed unlikely he had the presence of mind to be sarcastic, so I took him seriously.
Title: Re: Memory Leak
Post by: Maddox on May 19, 2005, 10:09 PM
Quote from: Kp on May 19, 2005, 05:57 PM
Quote from: Maddox on May 19, 2005, 05:03 PMYou are not a very good detector of sarcasm.  :P

Based on the original poster's comments, it seemed unlikely he had the presence of mind to be sarcastic, so I took him seriously.

I think you need to get out more.
Title: Re: Memory Leak
Post by: MyndFyre on May 19, 2005, 10:40 PM
Quote from: Maddox on May 19, 2005, 10:09 PM
Quote from: Kp on May 19, 2005, 05:57 PM
Quote from: Maddox on May 19, 2005, 05:03 PMYou are not a very good detector of sarcasm.  :P

Based on the original poster's comments, it seemed unlikely he had the presence of mind to be sarcastic, so I took him seriously.

I think you need to get out more.
I think Kp's response was perfectly understandable.  *shrug*
Title: Re: Memory Leak
Post by: Yoni on May 20, 2005, 01:59 AM
A memory leak is what happens when you open a drawer, but forget to close it.
Title: Re: Memory Leak
Post by: Warrior on May 20, 2005, 05:46 AM
..rofl
Title: Re: Memory Leak
Post by: Maddox on May 20, 2005, 08:49 AM
Quote from: MyndFyre on May 19, 2005, 10:40 PM
Quote from: Maddox on May 19, 2005, 10:09 PM
Quote from: Kp on May 19, 2005, 05:57 PM
Quote from: Maddox on May 19, 2005, 05:03 PMYou are not a very good detector of sarcasm.  :P

Based on the original poster's comments, it seemed unlikely he had the presence of mind to be sarcastic, so I took him seriously.

I think you need to get out more.
I think Kp's response was perfectly understandable.  *shrug*

Yeah, if you live under a rock.
Title: Re: Memory Leak
Post by: R.a.B.B.i.T on May 20, 2005, 10:37 AM
I live under a rock, can I have a cookie?