Alice Community  

Go Back   Alice Community > General Discussion > Questions and Comments

Reply
 
Thread Tools Display Modes
Memory leaks?
Old
Chris.Foree
Guest
 
Status:
Posts: n/a
Question Memory leaks? - 03-21-2008, 05:07 PM

I just started my intro to programming class this past January. We have been using Alice as our core instruction and reference. My professor told us the first week while working with Alice that the Alice program itself had a bad memory leak. As a result of this computer performance would degrade while using the program. I guess my question is what causes the memory leak and how can I avoid memory leaks in programs I write in Alice? If the Alice program itself has a bad memory leak, would it even make a difference if my programs did not have memory leaks? Can anyone clarify?
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 03-21-2008, 09:09 PM

Quote:
Originally Posted by Chris.Foree View Post
I just started my intro to programming class this past January. We have been using Alice as our core instruction and reference. My professor told us the first week while working with Alice that the Alice program itself had a bad memory leak. As a result of this computer performance would degrade while using the program. I guess my question is what causes the memory leak and how can I avoid memory leaks in programs I write in Alice? If the Alice program itself has a bad memory leak, would it even make a difference if my programs did not have memory leaks? Can anyone clarify?
I suggest that you ask your professor to provide the technical details regarding the Alice memory leak that he or she told you about. Since the professor seems to have knowledge of a specific memory leak, surely the professor can provide the technical details on the memory leak. Anyone else would simply be guessing as to what your professor is referring to.

Once you learn the technical details, please provide that information to the rest of us.

Professor Richard G. Baldwin

Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 03-22-2008, 11:23 AM

Not sure what your professor is referring to, but one "memory leak" problem deals with the use of virtual memory with large files. Virtual memory is (essentially) disk space reserved for scratch use when your regular memory is to small to hold all of the active data (something that can easily happen if you have both Alice and Open Office (a Java based Office-like program) running and both large graphics files and large animations).

The virual memory must be cleared when the data is no longer needed, part of a process called "garbage collection." This can cause problems, since you also don't want to erase data too soon - and apparently earlier versions of Java had some specific problems in this area.

In Alice, what happens is that eventually there isn't enough virtual memory left to support the program (it leaked off?) and the program just hangs up with memory management tasks - sometimes before the problem is actually detected and you get a "virtual memory low" warning. Per Lance A., to really clear this problem requires rebooting the machine.

I particularly mention Open Office since it can cause the problem before you start running Alice - or Alice can get close to exhausting the available virtual memory and then Open Office will actually be the program that hangs up.

Note that this problem should go away with "enough" memory - but "enough memory" is an oxymoron.
   
Reply With Quote
Old
Chris.Foree
Guest
 
Status:
Posts: n/a
Default 03-22-2008, 11:50 AM

Quote:
Originally Posted by DrJim View Post
Not sure what your professor is referring to, but one "memory leak" problem deals with the use of virtual memory with large files. Virtual memory is (essentially) disk space reserved for scratch use when your regular memory is to small to hold all of the active data (something that can easily happen if you have both Alice and Open Office (a Java based Office-like program) running and both large graphics files and large animations).

The virual memory must be cleared when the data is no longer needed, part of a process called "garbage collection." This can cause problems, since you also don't want to erase data too soon - and apparently earlier versions of Java had some specific problems in this area.

In Alice, what happens is that eventually there isn't enough virtual memory left to support the program (it leaked off?) and the program just hangs up with memory management tasks - sometimes before the problem is actually detected and you get a "virtual memory low" warning. Per Lance A., to really clear this problem requires rebooting the machine.

I particularly mention Open Office since it can cause the problem before you start running Alice - or Alice can get close to exhausting the available virtual memory and then Open Office will actually be the program that hangs up.

Note that this problem should go away with "enough" memory - but "enough memory" is an oxymoron.
Thanks! That does clarify the term memory leak. I will still have to ask my professor what "leak" he is talking about. I guess the term "memory leak" is somewhat ironic becuase memory is not actually lost, rather it is allocated within a program and due to programming flaws and can't be accessed again without a reboot. Wild and crazy stuff this programming is....maybe that is why I am enjoying it so much!! Hee.. Hee..
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 03-22-2008, 01:37 PM

Quote:
Originally Posted by Chris.Foree View Post
Thanks! That does clarify the term memory leak. I will still have to ask my professor what "leak" he is talking about. I guess the term "memory leak" is somewhat ironic becuase memory is not actually lost, rather it is allocated within a program and due to programming flaws and can't be accessed again without a reboot. Wild and crazy stuff this programming is....maybe that is why I am enjoying it so much!! Hee.. Hee..
Fortunately, although memory leaks are bad, they normally don't require a reboot to recover. However, that may be the case when virtual memory is involved, but that is just a guess on my part.

Typically, when a program suffers from a memory leak, terminating and restarting the program is sufficient to resolve the problem. For example, about 15 years ago, I did a lot of work with extremely large Excel spread sheets. At that time, Excel had a memory leak. After working for a long period of time, I would get an "out of memory" error. I was able to recover from the error by saving my spreadsheet, terminating, and restarting Excel. Having done that, I could work for another long period of time before getting another error and having to go through the same recovery process again. Normally, when a program terminates, the operating system is able to recover all of the memory that has been allocated to and by the program, but that may not be the case for virtual memory.

Getting back to one of your original questions, without knowing the technical details of the memory leak to which your professor is referring, it is very difficult to suggest what, if anything, an Alice programmer could do to prevent the problem.

While there may be procedures that an Alice programmer could avoid to reduce the probability of a memory leak, since the Alice programmer has no control whatsoever over the allocation and recovery of memory, it is unlikely that an Alice programmer could do anything directly to prevent a memory leak. The Alice programming language is one level removed from the level where the programmer has control over the allocation and recovery of memory. You have to get down to the Java (C++, or C#) level to have that kind of control.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm

Last edited by DickBaldwin; 03-22-2008 at 01:38 PM. Reason: correct grammar
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 03-22-2008, 06:41 PM

As Dr. Jim stated, I did say that at times I need to reboot to flush memory after using Alice. However I'm not sure my problem is attributable to 'memory leaks' as much as it might be attributable to memory not being "cleared/released" when the program no longer requires it.

Java has 'garbage collection' - However, I can find NO information concerning how this is implemented. Is it cleared if your program errors out ? Java was interrupted in the process of running a program - does it know to go back and clear memory it has reserved? I seriously doubt it . . .

I'm not sure how Python clears memory when it is no longer required, or errors out.

In C we have to physically release memory when it is no longer required.

Where Alice falls within these languages I am uncertain.

However since Alice 3.0 is a Work In Progress (WIP) perhaps we don't have to concern ourselves with this.
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 03-22-2008, 08:30 PM

Quote:
Originally Posted by lanceA View Post
As Dr. Jim stated, I did say that at times I need to reboot to flush memory after using Alice. However I'm not sure my problem is attributable to 'memory leaks' as much as it might be attributable to memory not being "cleared/released" when the program no longer requires it.

Java has 'garbage collection' - However, I can find NO information concerning how this is implemented. Is it cleared if your program errors out ? Java was interrupted in the process of running a program - does it know to go back and clear memory it has reserved? I seriously doubt it . . .

I'm not sure how Python clears memory when it is no longer required, or errors out.

In C we have to physically release memory when it is no longer required.

Where Alice falls within these languages I am uncertain.

However since Alice 3.0 is a Work In Progress (WIP) perhaps we don't have to concern ourselves with this.
The use of garbage collection versus purposeful c-style delete commands was highly controversial in the late 90s when Java first became prominent. However, I believe that Microsoft later adopted garbage collection for C#, Managed C++, and VB.net, and that seems to tamped the controversy down somewhat.

I also doubt that the Java virtual machine and its garbage collector knows to go back and clear memory when it errors out. However, I have assumed for years (perhaps incorrectly) that whenever a program written in any language is running under the auspices of the operating system, when that program terminates for any reason, the OS is smart enough to recover all of the memory that was occupied by the terminated program. My reasoning has been (again possibly incorrect) that the program allocates memory only with the permission of the OS and therefore the OS knows all about the memory that the program has allocated. Therefore, the OS should be able to recover all of that memory. After all, the Java virtual machine is simply another executable program.

However, when I was in industry, I had a poster on my wall that showed a cartoon character of a little cowboy with a big gun on his hip and a big hole in his foot and a caption that read: "Don't never assume nothin."

That would probably be good advice for me to consider in the case of garbage collection, be it Java, C#, VB.net, or Managed C++.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 03-24-2008, 06:00 PM

The only times I know I have had to reboot to clear an apparent error was when I had both Open Office (a Sun/Java version of Microsoft Office) and Alice open with large files at the same time. (Open Office has a very nice drawing program which I was using for textures.) That started me with the habit of automatically rebooting after working with very large files using any program - that may be (and probably is) overkill, but it doesn't cost much in the way of time and effort.

I did assume (carefully watching for things aimed at my feet and other body parts) that the problem was that the Java virtual machine didn't actually shut down when the programs were terminated and hence the reboot was required. Seemed reasonable but have no idea if this was correct.

Is there any reason to think Alice 3.0 will fix the problem completely? (I know we can expect great improvements just from the progress with Java.)
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 03-24-2008, 07:28 PM

Quote:
Originally Posted by DrJim View Post
...

I did assume (carefully watching for things aimed at my feet and other body parts) that the problem was that the Java virtual machine didn't actually shut down when the programs were terminated and hence the reboot was required. Seemed reasonable but have no idea if this was correct.

Is there any reason to think Alice 3.0 will fix the problem completely? (I know we can expect great improvements just from the progress with Java.)
The Java Virtual Machine is just an executable program, written in either C or C++, not greatly different from any other executable program written in C or C++. I'm fairly confident that the virtual machine wasn't written in Java. The file name for the virtual machine is simply java.exe. To start the virtual machine from the Windows command prompt, you simply enter java at the command prompt. However, if you don't also provide the name of a class file as a command-line parameter the virtual machine will display some usage information and terminate. If you do provide the name of a class file as a command prompt, the virtual machine will start executing the contents of the class file as a Java program.

As to whether Alice 3.0 will be an improvement in this regard, only time will tell. However, the CMU position is that you will be able to do anything with Alice 3.0 that you can do with Java, and that will certainly be an improvement.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 03-24-2008, 08:31 PM

Quote:
Originally Posted by DickBaldwin View Post
I'm fairly confident that the virtual machine wasn't written in Java.
That would almost rival a self-eating watermellon.

The question I have is what ends virtual machine execution if you have multiple programs running that use it - are several copies of it also executing or are the programs run as multiple threads on one virtual machine? In either case, there must be shared memory management both within (or between) the virtual machine(s) and other programs running under the master OS. I had assumed (that bad word again) that this was where the problems that caused the need for the reboot came in.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2018, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.