skip to Main Content

I’d like to delete all of the data inside of specific node, without knowledge of specific id’s. I’ve written some function within button click:

        val dbref = FirebaseDatabase.getInstance().reference.child("Message")
    dbref.addValueEventListener(object : ValueEventListener {
        override fun onDataChange(snapshot: DataSnapshot) {
            for (data in snapshot.children) {
                data.ref.removeValue()
            }
        }

        override fun onCancelled(error: DatabaseError) {
            TODO("Not yet implemented")
        }
    })

Whenever I’ll click the button, the app crash after a couple of seconds, with this stack trace:

   2023-10-24 15:08:55.651 15854-15878 OpenGLRenderer          com.example.myapplication            E  Unable to match the desired swap behavior.
2023-10-24 15:08:58.479   571-1625  TaskPersister           system_server                        E  File error accessing recents directory (directory doesn't exist?).
2023-10-24 15:09:24.970 15854-15881 RunLoop                 com.example.myapplication            E  Firebase Database encountered an OutOfMemoryError. You may need to reduce the amount of data you are syncing to the client (e.g. by using queries or syncing a deeper path). See https://firebase.google.com/docs/database/ios/structure-data#best_practices_for_data_structure and https://firebase.google.com/docs/database/android/retrieve-data#filtering_data
                                                                                                    java.lang.OutOfMemoryError: Failed to allocate a 16 byte allocation with 692344 free bytes and 676KB until OOM, target footprint 201326592, growth limit 201326592; giving up on allocation because <1% of heap free after GC.
                                                                                                        at java.lang.Long.valueOf(Long.java:1252)
                                                                                                        at com.google.firebase.database.core.WriteTree$1.evaluate(WriteTree.java:238)
                                                                                                        at com.google.firebase.database.core.WriteTree$1.evaluate(WriteTree.java:234)
                                                                                                        at com.google.firebase.database.core.WriteTree.layerTree(WriteTree.java:433)
                                                                                                        at com.google.firebase.database.core.WriteTree.calcCompleteEventCache(WriteTree.java:243)
                                                                                                        at com.google.firebase.database.core.SyncTree.calcCompleteEventCache(SyncTree.java:999)
                                                                                                        at com.google.firebase.database.core.Repo.setValue(Repo.java:467)
                                                                                                        at com.google.firebase.database.DatabaseReference$1.run(DatabaseReference.java:290)
                                                                                                        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
                                                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:264)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:307)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
2023-10-24 15:09:26.347 15854-15881 RunLoop                 com.example.myapplication            E  Firebase Database encountered an OutOfMemoryError. You may need to reduce the amount of data you are syncing to the client (e.g. by using queries or syncing a deeper path). See https://firebase.google.com/docs/database/ios/structure-data#best_practices_for_data_structure and https://firebase.google.com/docs/database/android/retrieve-data#filtering_data
                                                                                                    java.lang.OutOfMemoryError: Failed to allocate a 426856 byte allocation with 163360 free bytes and 159KB until OOM, target footprint 201326592, growth limit 201326592
                                                                                                        at java.util.Arrays.copyOf(Arrays.java:3553)
                                                                                                        at java.util.Arrays.copyOf(Arrays.java:3522)
                                                                                                        at java.util.ArrayList.grow(ArrayList.java:244)
                                                                                                        at java.util.ArrayList.grow(ArrayList.java:251)
                                                                                                        at java.util.ArrayList.add(ArrayList.java:461)
                                                                                                        at java.util.ArrayList.add(ArrayList.java:474)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.drainTo(ScheduledThreadPoolExecutor.java:1280)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.drainTo(ScheduledThreadPoolExecutor.java:1263)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.drainQueue(ThreadPoolExecutor.java:862)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.shutdownNow(ThreadPoolExecutor.java:1425)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor.shutdownNow(ScheduledThreadPoolExecutor.java:876)
                                                                                                        at com.google.firebase.database.android.AndroidPlatform$1.handleException(AndroidPlatform.java:106)
                                                                                                        at com.google.firebase.database.core.utilities.DefaultRunLoop$1.afterExecute(DefaultRunLoop.java:89)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
2023-10-24 15:09:26.349 15854-15882 AndroidRuntime          com.example.myapplication            E  FATAL EXCEPTION: TubeSockReader-1
                                                                                                    Process: com.example.myapplication, PID: 15854
                                                                                                    java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@a687cc3[Not completed] rejected from com.google.firebase.database.core.utilities.DefaultRunLoop$1@522e072[Shutting down, pool size = 1, active threads = 1, queued tasks = 463677, completed tasks = 11460]
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2082)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:842)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:345)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:569)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:712)
                                                                                                        at com.google.firebase.database.connection.WebsocketConnection$WSClientTubesock.onError(WebsocketConnection.java:106)
                                                                                                        at com.google.firebase.database.tubesock.WebSocket.runReader(WebSocket.java:432)
                                                                                                        at com.google.firebase.database.tubesock.WebSocket.access$000(WebSocket.java:47)
                                                                                                        at com.google.firebase.database.tubesock.WebSocket$2.run(WebSocket.java:143)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
2023-10-24 15:09:26.349 15854-15854 AndroidRuntime          com.example.myapplication            E  FATAL EXCEPTION: main
                                                                                                    Process: com.example.myapplication, PID: 15854
                                                                                                    java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@43fb527[Not completed] rejected from com.google.firebase.database.core.utilities.DefaultRunLoop$1@522e072[Shutting down, pool size = 1, active threads = 1, queued tasks = 463677, completed tasks = 11460]
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2082)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:842)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:345)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:569)
                                                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:712)
                                                                                                        at com.google.firebase.database.core.utilities.DefaultRunLoop.scheduleNow(DefaultRunLoop.java:105)
                                                                                                        at com.google.firebase.database.core.Repo.scheduleNow(Repo.java:304)
                                                                                                        at com.google.firebase.database.DatabaseReference.setValueInternal(DatabaseReference.java:286)
                                                                                                        at com.google.firebase.database.DatabaseReference.setValue(DatabaseReference.java:159)
                                                                                                        at com.google.firebase.database.DatabaseReference.removeValue(DatabaseReference.java:437)
                                                                                                        at com.example.myapplication.MainActivity$onClick$1.onDataChange(MainActivity.kt:52)
                                                                                                        at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:75)
                                                                                                        at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63)
                                                                                                        at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                        at android.os.Looper.loop(Looper.java:294)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8177)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
---------------------------- PROCESS ENDED (15854) for package com.example.myapplication ----------------------------
2023-10-24 15:09:26.396 30365-30388 OpenGLRenderer          com.example.currencyexchange         E  Unable to match the desired swap behavior.
2023-10-24 15:09:26.417   419-419   BpTransact...edListener surfaceflinger                       E  Failed to transact (-32)
2023-10-24 15:09:29.899   571-1625  TaskPersister           system_server                        E  File error accessing recents directory (directory doesn't exist?).
2023-10-24 15:10:29.373   571-767   ClipboardService        system_server                        E  Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:10:29.378   571-768   ClipboardService        system_server                        E  Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:11:24.686   571-767   ClipboardService        system_server                        E  Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:11:24.688   571-768   ClipboardService        system_server                        E  Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:11:28.275   571-767   ClipboardService        system_server                        E  Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:11:28.401   571-767   ClipboardService        system_server                        E  Denying clipboard access to com.android.chrome, application is not in focus nor is it a system service for user 0
2023-10-24 15:11:52.889  5250-10954 WakeLock                com.google.android.gms.persistent    E  GCM_HB_ALARM release without a matched acquire!
2023-10-24 15:11:57.631 16102-16102 gle.android.tts         pid-16102                            E  Not starting debugger since process cannot load the jdwp agent.
2023-10-24 15:11:58.051 16149-16149 equicksearchbox         pid-16149                            E  Not starting debugger since process cannot load the jdwp agent.
2023-10-24 15:11:58.629  5250-5345  bwfc                    com.google.android.gms.persistent    E  Phenotype API error. Event # edax@b9088f2a, EventCode: 5 [CONTEXT service_id=51 ]
                                                                                                    bwdx: 29501: Stale snapshot for com.google.android.libraries.search.googleapp.device#com.google.android.googlequicksearchbox(change count changed - expected 10  but was 9)
                                                                                                        at bwfg.b(:com.google.android.gms@[email protected] (190800-535401451):16)
                                                                                                        at bwff.g(:com.google.android.gms@[email protected] (190800-535401451):0)
                                                                                                        at bwfc.e(:com.google.android.gms@[email protected] (190800-535401451):4)
                                                                                                        at bwfc.f(:com.google.android.gms@[email protected] (190800-535401451):2)
                                                                                                        at avsy.eo(:com.google.android.gms@[email protected] (190800-535401451):1)
                                                                                                        at avtf.run(:com.google.android.gms@[email protected] (190800-535401451):14)
                                                                                                        at dfhf.run(:com.google.android.gms@[email protected] (190800-535401451):2)
                                                                                                        at aced.c(:com.google.android.gms@[email protected] (190800-535401451):6)
                                                                                                        at aced.run(:com.google.android.gms@[email protected] (190800-535401451):8)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at acjn.run(:com.google.android.gms@[email protected] (190800-535401451):0)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
2023-10-24 15:11:58.636 16102-16145 tflite                  pid-16102                            E  third_party/tensorflow/lite/core/subgraph.cc:903 tensor.data.raw != nullptr was not true.
2023-10-24 15:11:59.247  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.247  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.248  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.248  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.249  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.253  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.254  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.255  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.255  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.256  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.256  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.256  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_en-US is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.256  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.257  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.275  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.275  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.276  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.277  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.277  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.278  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.278  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.279  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.279  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.280  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.281  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.282  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_en-US is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.283  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.283  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.338  5250-12348 NanoAppLogging          com.google.android.gms.persistent    E  Failed to begin contexthub communication
2023-10-24 15:11:59.578  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_en-US is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.582  1559-2100  SP.Service.AiAi         com.google.android.as                E  captions_i18n_v0_mandatory is opened by other clients. It will stay open until all clients close it.
2023-10-24 15:11:59.763  5376-5455  MDD                     com.google.android.gms               E  FileGroupManager: Trying to add expired group enpromo-state-config.
2023-10-24 15:12:00.053  5376-25996 Pay                     com.google.android.gms               E  [Migration operation] Active tapandpay account not found! [CONTEXT service_id=198 ]

When I’ve wanted to add new value to the database, I’ve implemented something wrong, so I have a multiple keys with same value, instead of just one. Now, I just want to "wipe" this node.

2

Answers


  1. Try the following…

    val dbref = FirebaseDatabase.getInstance().reference.child("Message")
    dbref.removeValue()
    
    Login or Signup to reply.
  2. You’re getting the following error:

    Firebase Database encountered an OutOfMemoryError. You may need to reduce the amount of data you are syncing to the client (e.g. by using queries or syncing a deeper path).

    Because your Message node that you’re trying to read, contains much more data that can fit into your memory, hence the error.

    Besides that, there is no need to read a node in order to delete it. You can simply call DatabaseReference#removeValue() directly on the desired node:

    val dbref = FirebaseDatabase.getInstance().reference.child("Message")
    dbref.removeValue().addOnCompleteListener { 
        if (it.isSuccessful) {
            Log.d(TAG, "The node is successfully deleted.")
        } else {
            Log.d(TAG, "Failed with: ${it.exception?.message}") //👈
        }
    }
    

    When you perform asynchrony operations, never ignore potential errors.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search