Firebase observeSingleEvent stays in memory

前端 未结 2 429
一整个雨季
一整个雨季 2021-02-05 04:20

My app uses firebase\'s observeSingleEventOfType quite a fair bit and I came to realise that my app\'s memory increase over time. I have commented out all my code except a test

2条回答
  •  一个人的身影
    2021-02-05 04:27

    I think this way it will help in xcode too. I have done in my android application.

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("BLAH_BLAH_STRING");
    
                // Attach a listener to read the data at our posts reference
                ref.addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        // Do Some Stuff
                        ref.removeEventListener(this);
                        ref = null;
    
                    }
    
                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                    }
                });
    

    Or in iOS , I guess they have different methods to be used.

    removeAllObservers and removeObserverWithHandle:

    Please try with the given two methods above.

提交回复
热议问题