Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

258
Visualizações
Does using Spring boot with javafx will consume a lot of memory?

I'm willing to use Spring boot technology in my JavaFX application (to get the advantage of its dependency injection), but I'm wondering about the consequences on the memory, as you know any class with a "component" notation will be loaded to the MetaSpace (since it Spring boot will create a static object from it), so with tens of JavaFx view controllers loaded to the MetaSpace they will never get garbage collected from the launching of the application to the end, which is obviously a bad thing, is there any way to get around of this issue?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You write in comments:

JavaFX applications when the view controller doesn't get garbage collected means also the view objects will always stay there TableViews,ListViews,Panes ... which may take some important space

But I don’t think it needs to be that way.

The controller instance which references the Java nodes is just a Java object like any other and will be available for garbage collection when there are no more references to it in the JVM.

Let’s say you configure your JavaFX SpringBoot integration like this:

  • Adding Spring Dependency Injection in JavaFX (JPA Repo, Service)

So you configure your controller factory to use Spring beans:

fxmlLoader.setControllerFactory(
    springContext::getBean
);

Then your controllers are Spring beans whose scope you can control.

If you use prototype scope:

@Bean
@Scope("prototype")
public PersonController personControllerPrototype() {
    return new PersonController();
}

Then the behavior is as specified in:

  • Regarding the scope and garbage collection in Spring bean container

Spring does not manage the complete lifecycle of a prototype bean: the container instantiates, configures, and otherwise assembles a prototype object, and hands it to the client, with no further record of that prototype instance.

Typically you will create a controller and add a reference to the object tree that it instantiates into the scene graph. If you replace the tree in the scene graph when you navigate, and you don’t keep a reference to the controller anywhere, then the controller and any other associated nodes which have been removed from the scene graph can be garbage collected.

Or, if you wanted to just load the fxml once and keep the controller around forever you could use singleton scope to do that.

So basically, you can choose the scope and lifecycle of your controllers to be as best fits your application or the individual controllers that you are using.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda