Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Not a Question but a tutorial(Kinda)
Old
King Gamer(gorit)
Guest
 
Status:
Posts: n/a
Default Not a Question but a tutorial(Kinda) - 04-21-2010, 09:26 PM

I am sure anyone who uses akice knows the recursion memory leak issues. I have just found a work around that does not triger the memory leak. What you do is have 2 copys of a method linking each linking to the other copy. It is a endless loop without using a loop or using amethod that leaks memory. I found this out doing an experiment with endless loops today.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 04-21-2010, 09:59 PM

How do you know it doesn't cause a memory leak? It's still a computer process which uses processor power, which typically causes memory leaks when used in excess in Alice.


(')>
   
Reply With Quote
Old
jediaction
Senior Member
 
jediaction's Avatar
 
Status: Offline
Posts: 5,064
Join Date: Jul 2009
Location: Bel Air, Maryland
Default 04-22-2010, 08:18 AM

I have no diea what you king Gamer just said


Website: www.salokingames.com
FaceBook: www.facebook.com/SalokinGames
   
Reply With Quote
Old
King Gamer(gorit)
Guest
 
Status:
Posts: n/a
Default 04-22-2010, 04:06 PM

Ok, I will make an example.
Code:
Method 1 Code
increase world.variable ++ 
print world.variable
[METHOD 2]
Method 2 Code
increase world.variable ++ 
print world.variable
[Method 1]
If you run the methods it creates an infinite loop. To adress X it obviusly creates some leak but doesn't create the infinite loop and while leaks.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 04-23-2010, 01:13 AM

Well, I suppose if there was a copy of Alice that glitched when while statements were used it could be useful.


(')>
   
Reply With Quote
Old
flats
Guest
 
Status:
Posts: n/a
Default 04-23-2010, 09:05 AM

Quote:
Originally Posted by King Gamer(gorit) View Post
I am sure anyone who uses akice knows the recursion memory leak issues.
Are you saying that Alice does not deallocate the memory after closing a running world, or that your running world crashes after a while when using infinite recursion?
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 04-23-2010, 12:33 PM

Quote:
Originally Posted by flats View Post
Are you saying that Alice does not deallocate the memory after closing a running world, or that your running world crashes after a while when using infinite recursion?
The second one. Alice is infamous for getting clunky and slow when too many complex infinite loops are used.

I'd love to see someone test this and see if using several complex commands with this iteration method doesn't cause lag.


(')>
   
Reply With Quote
Old
King Gamer(gorit)
Guest
 
Status:
Posts: n/a
Default 04-23-2010, 02:16 PM

I do have to admit it has not been thourgholy test it and I am going to use this in my comp game. I think it may experience minor lag when going from method to method but will not make the glitchs that occur with infinite loops.
   
Reply With Quote
Old
flats
Guest
 
Status:
Posts: n/a
Default 04-24-2010, 07:51 AM

Quote:
Originally Posted by x2495iiii View Post
The second one. Alice is infamous for getting clunky and slow when too many complex infinite loops are used.
This isn't a even really a bug. Unless you really know what you're doing, you shouldn't ever use infinite recursion.

In short, there's a special bit of memory called the Call Stack that every program gets. The call stack keeps track of what the program is doing, what methods called what, so the program knows when to hand control to what bit of itself.

Imagine you have a ball of red thread - that's your call stack. Every time you talk to a friend, you hold the end of the string and hand them the ball. If you finish your coversation, the friend hands you the ball back. If you get interrupted, you friend holds onto a bit of string, hands the ball to the person that interrupted him, and they start talking. Then there's another interruption, and the string gets passed again.

The first case is a normal method call. The second is a recurive one. If your friends keep interrupting one another, eventually you'll run out of red string to trace the conversation back to how it started. This is a stack overflow, which is why Alice crashes when you use infinite recursion.


In general, if you can write a method just as well (or even almost as well) without using recursion, you should. A computer will always be better at a while loop than a recursive method.

Last edited by flats; 04-24-2010 at 07:55 AM.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 04-24-2010, 02:39 PM

I was actually talking about infinite loops, not necessarily recursive methods.

The problem is that some program elements require infinite loops. For example, RP has an infinite loop for the zombies' motion. This is because unless the game is paused or if you've won, the zombies have to keep moving. Another example would be collision detection, which has to constantly monitor the distance the moving object is from other objects in order to prevent the moving object from passing through other objects.

True, there are ways to limit the times which loops are used, like only having certain collision methods kick in when the moving object is reasonably close to a certain object, but otherwise certain elements of game-design require infinite loops.


(')>
   
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 ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.