Advertisements

Andrew Thompson schrieb:
> luca schwarz wrote:
> ...
>> this is strange. when i run my main i get this error:
>>
>> java.lang.OutOfMemoryError: Java heap space,
> ..
>> <code>
> ...
>> HIS_Control control = new HIS_Control();
>
> The problem apparently lies in HIS_Control(), he
> has apparently grown too fat, lazy and forgetful.
> So the solution to this one, is easy!
>
> HER_Control control = new HER_Control();
>
> If that does not fix the problem, you may need to
> be a little more specific about what happens in
> the mentioned code. An SSCCE* is generally
> *best* for explaining.
>
> * <http://www.physci.org/codes/sscce>
>
> Andrew T.
>
LOL. Good point
Tried it with HER, but nothing changed.

I believe to make a big mistake in my program-architecture.
To keep the problem small I reduced my classes to three.
The main, the control, and the model:

In your code, creating an instance of Control will create an instance
of Model, while creating an instance of Model will create an instance
of Control, so another instance of Model is created....And this process
runs on and on and on. That's why you have OutOfMemory problem.

On Jan 21, 6:40 pm, luca schwarz <> wrote:
> Andrew Thompson schrieb:
>
> > luca schwarz wrote:
> > ...
> >> this is strange. when i run my main i get this error:
>
> >> java.lang.OutOfMemoryError: Java heap space,
> > ..
> >> <code>
> > ...
> >> HIS_Control control = new HIS_Control();
>
> > The problem apparently lies in HIS_Control(), he
> > has apparently grown too fat, lazy and forgetful.
> > So the solution to this one, is easy!
>
> > HER_Control control = new HER_Control();
>
> > If that does not fix the problem, you may need to
> > be a little more specific about what happens in
> > the mentioned code. An SSCCE* is generally
> > *best* for explaining.
>
> > * <http://www.physci.org/codes/sscce>
>
> > Andrew T.LOL. Good point
> Tried it with HER, but nothing changed.
>
> I believe to make a big mistake in my program-architecture.
> To keep the problem small I reduced my classes to three.
> The main, the control, and the model:
>
> Main:
> <code>
> public class Start {
>
> public static void main(String[] args)
> {
> new Control();
> }
>
> }</code>
>
> Control:
> <code>
> public class Control
> {
> // Gui_Start guiStart = new Gui_Start();
> Model theModel = new Model();
>
> public Control()
> {
> //guiStart.setVisible(true);
> System.out.print("Control-Constructor run");
> }}</code>
>
> Model:
> <code>
> public class Model
> {
> Control theControl = new Control();}</code>
>
> If I run the main, I get an Exception.
> If I activate the object Gui_Start and the guiStart.setVisible(true) my
> computer crashes badly (cpu to the max and have to kill the eclipse
> javaw-process).
>
> Is it a thread-problem?
> Isn't it allowed to create objects of other classes in each single
> class? At least this is OOP!?
>
> Thanks for any help.
>
> Luca

Please refrain from top-posting. I find it most confusing.
> > ...
> >> this is strange. when i run my main i get this error:
> >>
> >> java.lang.OutOfMemoryError: Java heap space,
> > ..

Your complete code tells the story. But first, I
will repost your code as an SSCCE*. An SSCCE
is a form of the code inteded to be a (short) self-contained,
compilable example of the problem.

Your code fulfilled most of that description, but
an extra tip is to rework it so it is all in 'one Java file'**
which can be achieved by demoting classes with no
'main()' from 'public' to '' (default/package).

** This is not good for 'real' code, but we are just
trying to sort a basic problem - so it is fine.

I put some comments in that code, to indicate why it
is failing, but here is a version that (to the best of my
current understanding of the code - which is 'not much')
does what you are attempting to achieve (without the
recursive element!).

<sscce>
public class StartOnce {

public static void main(String[] args)
{
new Control();
}
}

class Control
{
// Declare model
Model theModel;

public Control()
{
// hand the model a reference to this Control
theModel = new Model(this);
System.out.println("Control-Constructor run");
}
}

Sorry for beeing a little confused. I try to solve problems by myself
and have to learn about the conventions of writing posts.

My main problem is to learn how to manage this: i have many classes and
all of them should be able to use the methods of every other class,
without get recursive.
I checked the net, but I couldn't find the any solution. No problem with
2 classes..but with more i get confused...sorry.

Andrew Thompson schrieb:
> luca schwarz wrote:
>> Andrew Thompson schrieb:
>>> luca schwarz wrote:
>
> Please refrain from top-posting. I find it most confusing.
>
>>> ...
>>>> this is strange. when i run my main i get this error:
>>>>
>>>> java.lang.OutOfMemoryError: Java heap space,
>>> ..
>
> Your complete code tells the story. But first, I
> will repost your code as an SSCCE*. An SSCCE
> is a form of the code inteded to be a (short) self-contained,
> compilable example of the problem.
>
> Your code fulfilled most of that description, but
> an extra tip is to rework it so it is all in 'one Java file'**
> which can be achieved by demoting classes with no
> 'main()' from 'public' to '' (default/package).
>
> ** This is not good for 'real' code, but we are just
> trying to sort a basic problem - so it is fine.
>
> Here is what I mean..
> <sscce>
> public class Start {
>
> public static void main(String[] args)
> {
> new Control();
> }
> }
>
> class Control
> {
> // GOTO create model
> Model theModel= new Model();
>
> public Control()
> {
> System.out.print("Control-Constructor run");
> }
> }
>
> class Model
> {
> // GOTO create control
> Control theControl= new Control();
> }
> </sscce>
>
> I put some comments in that code, to indicate why it
> is failing, but here is a version that (to the best of my
> current understanding of the code - which is 'not much')
> does what you are attempting to achieve (without the
> recursive element!).
>
> <sscce>
> public class StartOnce {
>
> public static void main(String[] args)
> {
> new Control();
> }
> }
>
> class Control
> {
> // Declare model
> Model theModel;
>
> public Control()
> {
> // hand the model a reference to this Control
> theModel = new Model(this);
> System.out.println("Control-Constructor run");
> }
> }
>
> class Model
> {
> // Declare control
> Control theControl;
>
> Model(Control control) {
> // associate the Control with our Model
> theControl = control;
> }
> }
> </sscce>
>
> Each of control and model have a reference to 'the'
> *single* instance of the other.
>
> * The full description of the SSCCE, along with
> why it is so handy for both debuggin and code
> postings, can be found here.
> <http://www.physci.org/codes/sscce/>
>
> BTW - these are very simple questions, and there is
> a group better suited to those learning Java, it is..
> comp.lang.java.help
> ..I highly recommend it.
>
> Andrew T.
>

You still are.
>...I try to solve problems by myself
> and have to learn about the conventions of writing posts.

True. One thing I requested you stop doing is 'top-post'.
Do you understand what it means?
Note that whenever I make a comment, I will put it directly
after what I am commenting on? The ideal way to post is to
do that, then trim any text not relevant to your reply.
> My main problem is to learn how to manage this:
....

Not as I see it. I think your main problems at this
instant are ..
a) carefully reading the instructions given*
b) getting people to continue helping you**

* I gave you a link to the SSCCE document earlier,
it details what it takes to make an SSCCE, here
is that link again.
>> * The full description of the SSCCE, along with
>> why it is so handy for both debuggin and code
>> postings, can be found here.
>> <http://www.physci.org/codes/sscce/>

The code you posted is not only hard to read,
since you removed all indentation (please put
'space' characters to give code a little indent,
as I did in my first example), but is sure
not an SSCCE.

** When people do not read what I have to say,
carefully, I become bored very quickly. You
almost have me at that stage already.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!