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

GraphIdentifiers don't seem to be cleaned-up #510

Open
jbehrens94 opened this issue Jun 15, 2022 · 10 comments
Open

GraphIdentifiers don't seem to be cleaned-up #510

jbehrens94 opened this issue Jun 15, 2022 · 10 comments

Comments

@jbehrens94
Copy link

Hi all,

I'm working on an app extension with extremely limited resources in terms of memory. I noticed that Swinject is claiming a lot of memory through GraphIdentifier, it'll increase quite a lot when doing regular actions throughout the extension.

Am I using Swinject wrong, or what should I do to minimise that amount in memory?

@jbehrens94
Copy link
Author

@mpdifran Who's able to help me on this? I don't know who the current contributors are, because I saw in an issue from 2020 that it looked like Swinject isn't maintained actively.

@jbehrens94
Copy link
Author

CC @yoichitgy Maybe you can help?

@mpdifran
Copy link
Member

I'll flag this to the contribution group! We are trying to continue maintaining this actively, and we've extended our contributors to help with that.

@jbehrens94
Copy link
Author

jbehrens94 commented Jun 22, 2022

Some additional information: I've got a set of structs conforming to Assembly that I then combine into a Assembler like this.

extension Assembler {
    static let filesExtension: Assembler = {
        let container = Container()
        let assembler = Assembler([
            DatabaseAssembly(),
            KeychainAssembly(),
            APIAssembly(),
            FileProviderAssembly(),
            FileProviderImplementationAssembly()
        ], container: container)

        return assembler
    }()
}

I'll then have a property private lazy var container = Assembler.filesExtension.resolver in my FileProviderExtension class. Does that seem correct to you, @mpdifran @yoichitgy?

@jbehrens94
Copy link
Author

@mpdifran @yoichitgy Can you confirm that my previously sent message contains a correct setup for Swinject?

@jbehrens94
Copy link
Author

Schermafbeelding 2022-07-27 om 11 07 52
Schermafbeelding 2022-07-27 om 11 07 03

The first screenshot is a clean start, the second screenshot is after an action in the app extension is finished. The memory Swinject is claiming seems to only be growing.

@mpdifran
Copy link
Member

@jbehrens94 yeah your setup looks correct, I don't see anything wrong with it.

@jbehrens94
Copy link
Author

What could be causes for Swinject to keep graph identifiers in memory and not clean up?

@jbehrens94
Copy link
Author

Same question for the Swinject.(Weak..) things

@bbrk24
Copy link

bbrk24 commented Sep 12, 2022

I investigated this a little, and from what I can tell, the GraphIdentifier and Weak<Any> objects are being held onto by GraphStorage. Perhaps instead of [GraphIdentifier: Weak<Any>], it needs some kind of WeakDictionary<GraphIdentifier, Any>.

Edit: On platforms with the Objective-C runtime, this is available as NSMapTable<GraphIdentifier, AnyObject>.weakToWeakObjects(). Some local testing shows that using this does fix the issue. However, I don't believe that's present on Linux, so a solution using NSMapTable wouldn't be completely portable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants