.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
Out of memory
Old
  (#1)
Zacker
Project Leader, Lead Level Designer, Waypointer
 
Status: Offline
Posts: 337
Join Date: Mar 2004
Location: Denmark
Default Out of memory - 16-06-2004

The following java method/function causes the jvm to run out of memory:

public class Udforsk
{
//Obekter
//Kamp kamp = new Kamp();

//IO
//opret et Tastatur-objekt
Tastatur tast = new Tastatur();
int svar;

//
//opret et Sted-objekt
Sted sted = new Sted();

//Karakteregenskaber - fjende
String fjende_navn = "";
int fjende_styrke = 10;
int fjende_intelligens = 10;
int fjende_liv = 100;

public void udforsk()
{

//Sker der noget spændende?
if(Math.random()>0.5)
{
//Nope
System.out.println("Du finder intet interessant");
sted.skoven();
}
//Det gør der
else
{
if(Math.random()>0.5)
{
//Fjendetype 1
fjende_navn = "blåmejse";
fjende_styrke = 1;
fjende_intelligens = 2;
fjende_liv = 5;
}
else
{
//Fjendetype 2
fjende_navn = "ulv";
fjende_styrke = 6;
fjende_intelligens = 4;
fjende_liv = 30;
}
System.out.println("Du møder en" + fjende_navn);

//Er man opdaget?
if (Math.random()>0.5)
{
//Fjenden har ikke opdaget spilleren endnu,
//og man kan derfor nå at træffe et valg
System.out.println("Den har endnu ikke opdaget dig");
System.out.println("Hvad vil du?");
System.out.println("1 - Angribe");
System.out.println("2 - Flygte");

svar = tast.læsHeltal();

if(svar==1)
{
//kamp.angrib();
}
else if(svar==2)
{
//kamp.flygt();
}
else
{
System.out.println(svar + " er ikke et gyldigt svar");
}

}
//Fjenden har opdaget spilleren og angriber
else
{


}


}

}

}
  
Reply With Quote
Re: Out of memory
Old
  (#2)
botman
Super Moderator
 
Status: Offline
Posts: 280
Join Date: Jan 2004
Location: Plano, TX
Default Re: Out of memory - 17-06-2004

Does "Tastatur" or "Sted" create a "Udforsk" object (thus creating an infinite recursive loop)?

You probably shouldn't be "new"ing other objects inside Udforsk unless you know that those object (or objects created inside those objects, or objects created inside those objects created inside those objects, etc) don't wind up creating a Udforsk object (making it infinitely recursive).

botman
  
Reply With Quote
Re: Out of memory
Old
  (#3)
BAStumm
Member
 
BAStumm's Avatar
 
Status: Offline
Posts: 138
Join Date: Jan 2004
Location: Spokane, WA USA
Default Re: Out of memory - 17-06-2004

Bah infinite loops are no problem in linux!

Quote:
"We all know Linux is great...it does infinite loops in 5 seconds."
(Linus Torvalds about the superiority of Linux on the Amterdam
Linux Symposium)






  
Reply With Quote
Re: Out of memory
Old
  (#4)
Zacker
Project Leader, Lead Level Designer, Waypointer
 
Status: Offline
Posts: 337
Join Date: Mar 2004
Location: Denmark
Default Re: Out of memory - 17-06-2004

Quote:
Does "Tastatur" or "Sted" create a "Udforsk" object (thus creating an infinite recursive loop)?
Yes one of them do. Changing that did not help, it still gives me the same silly error.

How do I access functions inside theese classes if I am not allowed to create a new instace of them?
As far as I know the only way to run methods from other classes is to do it this way.
  
Reply With Quote
Re: Out of memory
Old
  (#5)
Bert
Member
 
Status: Offline
Posts: 11
Join Date: Jan 2004
Default Re: Out of memory - 17-06-2004

You could use static methods so you don't actually need an instance of the class. Thjere seems nothing wrong with your code, though we don't have enough information ( also english comments/var names would be nice ) .
Check you aren't creating objects in a loop when it isn't really needed.

Last edited by Bert; 17-06-2004 at 18:42..
  
Reply With Quote
Re: Out of memory
Old
  (#6)
sfx1999
Member
 
sfx1999's Avatar
 
Status: Offline
Posts: 534
Join Date: Jan 2004
Location: Pittsburgh, PA, USA
Default Re: Out of memory - 20-06-2004

Memory leak?
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com