Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:23:38+00:00 2026-06-03T07:23:38+00:00

For a statement in a Java function: Xxx xxx = new Xxx() { public

  • 0

For a statement in a Java function:

Xxx xxx = new Xxx() {
    public Abc abc(final Writer out) {
        return new SomeFunction(out) {
            boolean isDone = false;
            public void start(final String name) {
                /* blah blah blah */
            }
        };
    }
};

Which variable, including the functions, are put on the heap, and which will be put on stack?

The reason I’m asking this is a segmentation fault in the JVM:

kernel: java[14209]: segfault at 00002aab04685ff8 rip 00002aaab308e4d0 rsp 00002aab04685ff0 error 6

00002aab04685ff8 and 00002aab04685ff0 are near, it seems that the stack is growing too fast. I try to investigate this part of code, and doubt whether it is the cause of problem when calling this function for many times. Is it possible that the stack is not cleared if it is referenced by some variables on the heap?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:23:40+00:00Added an answer on June 3, 2026 at 7:23 am

    The question of whether a particular object goes on the heap is a bit involved.

    In general, in Java, all objects are allocated on the heap, because a method may return or store a pointer to the object. If the object had been put on the stack, it would be overridden the next time a stack frame is put there.

    However, the HotSpot JIT compiler does something called Escape Analysis. This analysis finds out whether an object "escapes" the scope of the method by looking at the method’s code. If an object doesn’t escape, the compiler may safely allocate it on the stack.

    Wikipedia has some more information about Escape Analysis in Java, also regarding multi-threading and locking.


    Regarding the stack overflow: Stack frames on the call stack are always removed after the method finishes. Actually, there is not even a need to explicitly remove it. The next frame will just override what was previously there.

    Also, although in other languages (like C) it is possible to cause the stack to overflow by putting very large objects on the stack, I don’t think this could happen in Java. I expect the engineers at Sun (Oracle) to be smart enough to not make the VM store huge objects on the stack.

    So the only possibility to have a stack overflow is to have too many nested method invocations. Since the stack space is big enough to handle any "normal" method invocation nesting, a stack overflow normally indicates an infinite (or very large) recursion in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As per my understanding the following generic function in java: public static <T> T
We have a Prepared Statement in Java and we hear that it is different
How do i write an if statement in Java that displays Goodbye! if the
How should I write a statement in Java to produce JavaScript in a page
According to the documentation for getResultSet in java.sql.Statement , it says: Retrieves the current
I was reading this page and I found the following statement: MVC in Java
With the regular statement (just statement) I can put java enums into the queries
Does NetBeans have something akin to Set Next Statement/Instruction when debugging in Java?
I want to call java function from c++ which takes multiple parameters , I
I currently have a prepared statement in Java which uses the following SQL statement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.