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

353
Visualizações
Kotlin Android Extensions vs Android Data Binding Library, memory usage

I have a question about memory used in both cases ->Android Data Binding vs Android Kotlin Extensions. In which case will be less memory used on the device?

Kotlin Android-extension is calling first findViewById and after that, the result will be stored locally in a cache. and this means memory used.

DataBinding creates a path between layouts and activities/fragments through the binding class that was created.

My concern is to use the one that is more efficient when we think of memory usage on the user's device. Could anyone help me to figure out the answer? I tend to say dataBinding is more efficient. Here is a similar question but is not in the efficiency direction.

Thanks!

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

0

tldr: As far as I see it there is no difference depending memory usage, only if you don't use all views of the layout. Both cache the views, however andoid kotlin gets on demand while databinding initializes all. Depending performance, kotlin extensions is slightly(I would say in most cases not recognizable) faster than databinding during fragment/activity creation.

Documentation Kotlin Android Extensions:

Adds a hidden caching function and a field inside each Kotlin Activity. The method is pretty small so it doesn't increase the size of APK much. Replaces each synthetic property call with a function call.

How this works is that when invoking a synthetic property, where the receiver is a Kotlin Activity/Fragment class that is in module sources, the caching function is invoked. For instance, given

class MyActivity : Activity() fun MyActivity.a() { 
         this.textView.setText(“”) 
}

a hidden caching function is generated inside MyActivity, so we can use the caching mechanism.

However in the following case:

fun Activity.b() { 
    this.textView.setText(“”)
}

We wouldn't know if this function would be invoked on only Activities from our sources or on plain Java Activities also. As such, we don’t use caching there, even if MyActivity instance from the previous example is the receiver.

Reason: Kotlin uses synthetic properties and those are called on demand using caching function(Hence slight fast Activity/Fragment loading) while Databinding binds all views at once (that consumes slight more time).

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