Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Crashlytics and Performance causes a memory leak at app launch. #11725

Closed
RaccBigenner opened this issue Aug 24, 2023 · 18 comments · Fixed by #11802
Closed

Firebase Crashlytics and Performance causes a memory leak at app launch. #11725

RaccBigenner opened this issue Aug 24, 2023 · 18 comments · Fixed by #11802
Assignees
Labels
api: crashlytics api: performance sessions Changes pertaining to the Firebase Sessions SDK

Comments

@RaccBigenner
Copy link

Description

When I go to Firesotre, the CPU and memory increase and the app crashes.
It doesn't matter how much data you have, it can happen with more or less data.

If you do it on the real machine, it will crash as above, but if you do it on the simulator, the CPU and memory will increase, but it will not crash.

The following is repeatedly output on the simulator.

2023-08-20 22:09:22.810732+0900 xxx[10198:8177038] [connection] nw_connection_copy_protocol_metadata_internal_block_invoke [C580] Client called nw_connection_copy_protocol_metadata_internal on unconnected nw_connection

2023-08-20 22:09:14.007917+0900 xxx[10198:8177038] [connection] nw_connection_copy_connected_local_endpoint_block_invoke [C562] Client called nw_connection_copy_connected_local_endpoint on unconnected nw_connection

2023-08-20 22:10:02.785020+0900 xxx[10198:8177023] [connection] nw_connection_copy_connected_remote_endpoint_block_invoke [C659] Client called nw_connection_copy_connected_remote_endpoint on unconnected nw_connection

xxx is the application name.

Reproducing the issue

The relevant code is below.
I'm sure it's not elsewhere.

import FirebaseFirestoreSwift
import FirebaseFirestore

func toLoadFireStore(id: String, completion: @escaping (String) -> Void)  {
    
    Firestore.firestore().collection("users").document(id).getDocument { (snaps, error) in

        completion("")
        return

 }

Firebase SDK Version

10.14.0

Xcode Version

14.3.1

Installation Method

Swift Package Manager

Firebase Product(s)

Database, Firestore

Targeted Platforms

iOS

Relevant Log Output

2023-08-20 22:09:22.810732+0900 xxx[10198:8177038] [connection] nw_connection_copy_protocol_metadata_internal_block_invoke [C580] Client called nw_connection_copy_protocol_metadata_internal on unconnected nw_connection

2023-08-20 22:09:14.007917+0900 xxx[10198:8177038] [connection] nw_connection_copy_connected_local_endpoint_block_invoke [C562] Client called nw_connection_copy_connected_local_endpoint on unconnected nw_connection

2023-08-20 22:10:02.785020+0900 xxx[10198:8177023] [connection] nw_connection_copy_connected_remote_endpoint_block_invoke [C659] Client called nw_connection_copy_connected_remote_endpoint on unconnected nw_connection

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
Replace this line with the contents of your Package.resolved.

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@rizafran
Copy link
Contributor

Thanks for filing, @RaccBigenner. Could you share the complete stack trace of your issue to see what's causing it?

@milaGGL milaGGL self-assigned this Aug 24, 2023
@RaccBigenner
Copy link
Author

Thanks for filing, @RaccBigenner. Could you share the complete stack trace of your issue to see what's causing it?

I don't know what "the complete stack trace of your issue" is, but I will also provide the following information.

error handling

func toLoadFireStore(id: String, completion: @escaping (String) -> Void)  {
    
    Firestore.firestore().collection("users").document(id).getDocument { (snaps, error) in

        completion("success")
        return

        if let error {
            print("Error in toLoadFireStore: \(error.localizedDescription)")
            completion("notAccess")
            return
        }
        
        guard let document = snaps else {
            print("Document does not exist")
            completion("notFind")
            return
        }
        
        guard let data = snaps?.data() as? [String:Any] else {
            completion("isUnmatch")
            return
        }
        
        if let dataSize = try? JSONSerialization.data(withJSONObject: data, options: []).count {
            print("Data size in bytes: \(dataSize)")
        } else {
            print("Failed to calculate data size")
        }
}

Caller processing

toLoadFireStore(id: savedUserID) { result in
                        switch result {
 default: print("ok")
}

@morganchen12
Copy link
Contributor

Can you profile your app via Xcode Instruments and share the trace here?

@paulb777 paulb777 changed the title Accessing Firesotre causes a memory leak and crashes the app. Accessing Firestore causes a memory leak and crashes the app. Aug 24, 2023
@RaccBigenner
Copy link
Author

Xcode Instruments 経由でアプリをプロファイリングし、ここでトレースを共有できますか?

Untitled.trace.zip

How do you like this?

@morganchen12
Copy link
Contributor

There's two memory leaks here, one in GoogleMobileAds and one in FirebaseSessions. Unfortunately, the stack trace in Instruments is unsymbolicated. Can you share a sample project that demonstrates this leak?

For GoogleMobileAds, you can ask for help in this mailing list.

@morganchen12 morganchen12 added sessions Changes pertaining to the Firebase Sessions SDK and removed api: firestore needs-attention labels Aug 25, 2023
@RaccBigenner
Copy link
Author

Please specify how to share a sample project.

@milaGGL milaGGL removed their assignment Aug 28, 2023
@morganchen12
Copy link
Contributor

You can push a project to an empty GitHub repository and then post the link here, or try reproducing this bug in one of our quickstarts.

@RaccBigenner
Copy link
Author

You can push a project to an empty GitHub repository and then post the link here, or try reproducing this bug in one of our quickstarts.

Can I invite you to my private repository?
I would like you to take a look at the project there.

@RaccBigenner
Copy link
Author

You can push a project to an empty GitHub repository and then post the link here, or try reproducing this bug in one of our quickstarts.

Can I invite you to my private repository? I would like you to take a look at the project there.

Can you see it?

@morganchen12
Copy link
Contributor

@RaccBigenner sorry for the slow response. You can invite me to your private repository. I haven't received an invitation yet.

@RaccBigenner
Copy link
Author

@RaccBigenner sorry for the slow response. You can invite me to your private repository. I haven't received an invitation yet.

I invited you. See LogNestOfStory.xcodeproj.

@morganchen12 morganchen12 changed the title Accessing Firestore causes a memory leak and crashes the app. Firebase Crashlytics and Performance causes a memory leak at app launch. Sep 12, 2023
@morganchen12
Copy link
Contributor

The sessions leak is a regression of #11027. You can request help for the Google Ads memory leak here: https://support.google.com/admob/topic/12676598

I was not able to reproduce a crash in the app.

@RaccBigenner
Copy link
Author

The sessions leak is a regression of #11027. You can request help for the Google Ads memory leak here: https://support.google.com/admob/topic/12676598

I couldn't understand this.
Does this mean that Google Ads is the cause of the memory leak?
When I tried it, the crash occurred even when I skipped ad loading.

I was not able to reproduce a crash in the app.

Here are the steps to reproduce the app crash.

First, start it on the actual machine.

Next, enter the following into the transfer code input field as "引き継ぎID入力" on the title screen.
8825CE71-1E20-4287-9A86-76F907A45EA8

In that state, tap the title screen to start the game.

From there a memory leak occurs and the app crashes.

By the way, I don't know why you can't reproduce it in the simulator. It may be related to the cause of this problem.

@RaccBigenner
Copy link
Author

Please open this issue.

@morganchen12
Copy link
Contributor

I cannot sign your app to build it to a device. Does the crash occur if you disable or remove Firebase?

@RaccBigenner
Copy link
Author

I cannot sign your app to build it to a device. Does the crash occur if you disable or remove Firebase?

No, it doesn't happen.
This occurs only when communicating with firebase at a large capacity.

Is there any way I can pinpoint the problem?

@morganchen12
Copy link
Contributor

You can use the Allocations tool in Xcode Instruments to determine what is allocating the memory that causes the crash: https://developer.apple.com/documentation/xcode/gathering-information-about-memory-use

@firebase firebase locked and limited conversation to collaborators Oct 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: crashlytics api: performance sessions Changes pertaining to the Firebase Sessions SDK
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants