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

97
Visualizações
Prioritize objects for GC

I'm implementing an image cache that can will be heavy on memory usage so I'm keeping a SoftReference to image data so the GC can collect them under memory pressure.

However, each entry has an age so is there a way to tell a GC (which one?) to collect older entries instead of "random" ones?

I guess I could kind of do it myself by keeping strong references and removing entries on low freeMemory(), but that's kind of an "indirect free" (GC still has to kick-in to actually free the memory).

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

0

From the docs:

All soft references to softly-reachable objects are guaranteed to have been cleared before the virtual machine throws an OutOfMemoryError. Otherwise no constraints are placed upon the time at which a soft reference will be cleared or the order in which a set of such references to different objects will be cleared. Virtual machine implementations are, however, encouraged to bias against clearing recently-created or recently-used soft references.

Thus a sophisticated cache can, for example, prevent its most recently used entries from being discarded by keeping strong referents to those entries, leaving the remaining entries to be discarded at the discretion of the garbage collector.

This is from the JDK 11 java docs. In short, the answer is NO. I guess you could try to do crazy stuff with finalize but I would recommend against it. Your idea of using strong references might be the most viable.

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