-
Notifications
You must be signed in to change notification settings - Fork 6k
[ios] Convert FlutterPlatformViewsController to smart pointer #22082
[ios] Convert FlutterPlatformViewsController to smart pointer #22082
Conversation
| #pragma mark - Platform views | ||
|
|
||
| - (flutter::FlutterPlatformViewsController*)platformViewsController { | ||
| - (std::shared_ptr<flutter::FlutterPlatformViewsController>)platformViewsController { |
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.
Is this getting called at least once per frame? If so it may be desirable to pass back a const reference to allow any copying of the shared_ptr.
| FlutterViewController* view_controller_; | ||
| PlatformViewIOS* platform_view_; | ||
| FlutterPlatformViewsController* platform_views_controller_; | ||
| const std::shared_ptr<FlutterPlatformViewsController> platform_views_controller_; |
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.
Another big win here, nice.
|
|
||
| private: | ||
| FlutterPlatformViewsController* platform_views_controller_; | ||
| const std::shared_ptr<FlutterPlatformViewsController> |
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.
Nice!
gaaclarke
left a comment
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.
LGTM with a nit that I'd avoid copying the shared_ptr so much by using const references like i've mentioned in your other PR. Especially if this stuff is happening at least once a frame.
Also, a warning, you might be introducing a retain cycle. I'd run on device to make sure that FlutterPlatformViewsController gets deleted when you delete an engine. I don't know if FlutterPlatformViewsController, AccessibilityBridge, FlutterEngine, ExternalViewEmbedder form a cycle. But it's complicated enough that it might be.
|
I tried making it a const reference initially, but then ran into a problem where we pass in About the retain cycle, good point, I will take a look and see if it's a problem. |
That isn't a problem. There is an implicit constructor for shared_ptr that will create an rvalue whose reference will get passed on the stack, try this out: #include <memory>
#include <iostream>
namespace {
void foo(const std::shared_ptr<int>& ptr ) {
std::cout << ptr.get() << std::endl;
}
}
int main() {
foo(nullptr);
} |
|
@gaaclarke makes sense. I've moved them to be const references. |
|
I am still investigating to see if there is a retain cycle, and also looking to see if |
|
|
…r#22082) * Convert FlutterPlatformViewsController to smart pointer * have a const reference of platform views controller * change more stuff to references
Prior to this change
FlutterPlatformViewsControllerwas passed around as a raw pointer. This change makes it so that this is instead shared as a shared_ptr. This also makes the currentunique_ptrhold inFlutterEngine.mmto be a shared one.