-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Introduce a Shutdown method to DeviceControllerFactory #14723
Introduce a Shutdown method to DeviceControllerFactory #14723
Conversation
PR #14723: Size comparison from 22f5d22 to caa01ed Increases (3 builds for linux)
Full report (43 builds for cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be a void method.... I don't know what a consumer would do with an error return from this.
@kianooshkarami please fix "restyled" bits so this will request reviews... |
The new method would the symmetrical API for DeviceControllerFactory's already existing `Init()` API. What is the root of the problem? The problem we intend to solve is that we'd like to use `Shutdown()` method to shut down and clean up any memory/functionality enabled by `Init()` as opposed to waiting for the DeviceControllerFactory desctructor, which only happens once the program shuts down due to the nature of how DeviceControllerFactory is instantiated. DeviceControllerFactory can only be instantiated through ::GetInstance(), this method constructs DeviceControllerFactory only once for the life of the program (the constructor is a private method). Once the Init() is invoked, the `mSystemState` is allocated as shown in the following: ``` mSystemState = chip::Platform::New<DeviceControllerSystemState>(stateParams); ``` However, in DeviceControllerFactory's destructor, which currently is only invoked once the program shuts down, the deallocation of `mSystemState` is requested via `chip::Platform::Delete`. This can be problematic since the application will need to ensure `chip::Platform` memory stays initailized throughout the memory shutdown. Adding a shutdown methods allows the applications to have a symmetry between the initialization and shutdown sequence related to the DeviceControllerFactory
caa01ed
to
85a56f9
Compare
@bzbarsky-apple Thanks. Done, also changed the method to a void return. |
PR #14723: Size comparison from 1ee9366 to 85a56f9 Increases (3 builds for linux)
Full report (31 builds for cyw30739, efr32, k32w, linux, mbed, p6, qpg, telink)
|
Change overview
The new method would be the symmetrical API for DeviceControllerFactory's
already existing
Init()
API.What is the root of the problem?
The problem we intend to solve is that we'd like to use
Shutdown()
methodto shut down and clean up any memory/functionality enabled by
Init()
asopposed to waiting for the DeviceControllerFactory destructor, which only
happens once the program shuts down due to the nature of how
DeviceControllerFactory is instantiated.
DeviceControllerFactory can only be instantiated through ::GetInstance(),
this method constructs DeviceControllerFactory only once for the life of
the program (the constructor is a private method). Once the Init() is
invoked, the
mSystemState
is allocated as shown in the following:However, in DeviceControllerFactory's destructor, which currently is only
invoked once the program shuts down, the deallocation of
mSystemState
is requested via
chip::Platform::Delete
. This can be problematic sincethe application will need to ensure
chip::Platform
memory stays initializedthroughout the memory shutdown.
Adding a shutdown method allows the applications to have symmetry between
the initialization and shutdown sequence related to the
DeviceControllerFactory
Problem
What is being fixed?
Potentially Memory crashes when freeing
mSystemState
when the process shuts downTesting
How was this tested? (at least one bullet point required)
I could use some assistance if there are already existing unit tests that would help with the validation