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 8109179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:20:16+00:00 2026-06-06T01:20:16+00:00

So i am writing my first Java application using MVP pattern. One of MVPs

  • 0

So i am writing my first Java application using MVP pattern.
One of MVPs triads is one-way communications, basically Views are read only.

In case where there is only 1 model – 1 presenter – 1 view, would there be any backtrack of creating new presenter object and not holding reference to it anywhere else than model’s Observers list?

To make myself clear, this is how i would ‘normally’ do that:

private Result result;
private ResultPresenter resultPresenter;
public SomePresenter(SomeInterface view) {
    result = new Result();
    resultPresenter = new ResultPresenter(result, view.getResultView());
}

and this is how i would like to do that:

private Result result;
public SomePresenter(SomeInterface view) {
    result = new Result();
    new ResultPresenter(result, view.getResultView());
}

Where ResultPresenter is Observer of Result.

Primary question is, would ResultPresenter get cleared by garbage collector?

  • 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-06T01:20:18+00:00Added an answer on June 6, 2026 at 1:20 am

    Among other things (like initializing the view), ResultPresenter would instantiate or implement one or more Observers and register them on both the “result” and the “resultView”.
    Those classes would then hold references to the Observers and notify them as required.

    There are several ways to do that, with a common pattern being anonymous inner classes.
    Since those anonymous inner classes still hold references to their instantiator, the ResultPresenter will not be garbage collected.
    Another option is to instantiate top level classes as Observers.
    In this case, it depends on the Observers’ implementation whether the presenter is still referenced.
    Finally, the presenter itself can implement the Observers’ interfaces (one shudders at the thought). Obviously, model and view would then hold references to the presenter itself, though they think of it as an Observer, and it wouldn’t be garbage collected.

    Even if it would, that would only mean that you only need it to set up the presentation and link the objects to each other, and no longer require it afterwards, so no harm would be done.

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

Sidebar

Related Questions

I'm writing a Java Swing application for the Mac using Java 1.6. I've read
I'm writing my first Java EE application, using EJBs, Servlet, JSPs and the likes.
While writing my first Blackberry application using Java, I am confused between inheriting from
I have been writing a small java application (my first!), that does only a
I'm writing my first Java EE (EJB + Servlets etc.) application (please note: I'm
I'm writing my first LWUIT and Java ME application and trying to get button
I have some experience writing web applications in Java for class projects. My first
I'm writing HTML code for a Java servlet. I first write the code in
first of all, a preface: I'm writing a java class that creates temporary tables
Writing my first C# application...never touched the language before and not much of a

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.