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

  • SEARCH
  • Home
  • 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 9004267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:51:48+00:00 2026-06-16T00:51:48+00:00

If I create a class with nothing in it and then instantiate it n

  • 0

If I create a class with nothing in it and then instantiate it n times, is it possible for an OutOfMemory error to occur?

If I create a class and inside that class’ constructor create an instance of itself, will I have an infinite nesting of the same class? Will an OutOfMemory error occur?

Suppose I created a class which is supposed to get fed objects and check if they have any variable references to themselves, and include them in a list if they do not. How will my class react when the object passed to it is itself?

I’m mostly interested in how this applies to Java, as opposed to Cx , but still it would be interesting to note if they might behave differently.

  • 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-16T00:51:48+00:00Added an answer on June 16, 2026 at 12:51 am

    If I create a class with nothing in it and then instantiate it n times, is it possible for an OutOfMemory error to occur?

    Yes. If N is large enough.

    If I create a class and inside that class’ constructor create an instance of itself, will I have an infinite nesting of the same class?

    If you had an infinite amount of memory, yes. In practice you don’t, so the creation is bound to fail.

    Will an OutOfMemory error occur?

    Possibly. It is more likely that you will get a StackOverflow error … because what you are describing will create a recursion loop.

    Suppose I created a class which is supposed to get fed objects and check if they have any variable references to themselves, and include them in a list if they do not. How will my class react when the object passed to it is itself?

    It is impossible to say. It depends on how you implement the code to “check if they have any variable references to themselves”.


    You seem to be trying to explore the consequences of Russell’s Paradox for Java programs. The simple answer is that it has no consequences. A Java program that involves representations of sets will do whatever it has been coded to do. If you have a representation that allows a “set” to “contain” itself, then that will happen.

    There is one thing that should be obvious though. A simple representation of sets in Java will not allow you to represent sets with infinite numbers of elements. Memory (and stacks) in Java are finite. This doesn’t mean that it is impossible to represent all infinite sets. You just have to do it differently; e.g. using “lazy” data structures or a symbolic representation.


    It is tempting to think that a representation of sets might actually be mathematical sets, and you might be able to cause unspecified weirdness by triggering Russell’s paradox. In reality, no such thing will happen. Russell’s paradox asks the question “Does the set of all sets contain itself?”. But a program on a Turing-machine-equivalent computer cannot test all elements in a simple infinite set … let alone the set of all sets. Russell’s question is simply not a tractable problem. (But then, it was never intended to be tractable. It is really about exploring the limits of meaningful mathematics.)

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

Sidebar

Related Questions

If i create a singleton class then only one object of that class can
I need to create class Dog and PurebredDog extending Dog. Problem is that Dog
I need to create a class that will store a unique object elements. I
It's possible to create lots of memory-intensive objects and then abandon references to them.
I wanted to see if it's possible to create interfaces, inherit them, and then
I create class libraries, some which are used by others around the world, and
I am trying to create class properties for each element in an array. The
I have been curious about dynamically create class at runtime in C# and stumbled
I've found a task on some Java programming competition. One must create class Sentence
I need to create a class with two properties: LogOutput ExceptionOutput These properties (Actions<>)

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.