-
Notifications
You must be signed in to change notification settings - Fork 127
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
Possible memory leak when used with ASP.NET Core DI #148
Comments
We recently ran into a similar issue like you have, though we did notice it a bit later on. Since PubNub's documentation still makes no reference about the lifetime or their To reduce the amount of code changes that we had to make (Mostly in the creation of the
Hopefully PubNub will address this issue properly and either advise on using |
Our issues were resolved by adding Pubnub to the services collection with singleton lifetime. Until specified otherwise from Pubnub, the correct approach is: |
While investigating an issue with high CPU usage, a memory dump was taken of a long-running ASP.NET Core 6 server application (see below) that uses the PubNubPCL library.
The heap has a lot of retained instances of objects related to the PubNub API, particularly
PNConfguration
which, after about 3 days of continuous operation, occupies 107MB of heap space.I suspect the issue lies with the lifetime of the PubNub client in the DI container. We have a thin wrapper around the PubNub API that we inject with a Transient lifetime. The constructor creates a new PubNub object and configures it every time it is injected.
Based on the large number of
PubnubApi.ConcurrentDictionary
objects also on the heap, I believe the PubNub client is supposed to have a Singleton lifetime, but I could not find any guidance in the documentation regarding DI containers.Can you confirm the expected lifetime of the PubNub client? Is it expected to be a Singleton, or can it be constructed as needed in a long-running service?
Here is the relevant part of the heap analysis created with
dotnet-dump
. The command used wasdumpheap -stat -live
(statistical analysis of live objects only).The text was updated successfully, but these errors were encountered: