1

I am working on a plugin-based application which has different plugins. Each plugin is independent of the others. I am also using the Google Places API as a plugin in it. There is an option to refresh the plugin in case of any error. However, whenever I refresh the plugin, it restarts and spawns new threads every time. In the case of other plugins based on the Google Sleep API, etc., this problem does not occur. However, the Places API creates new threads internally every time I refresh it, and they are not deleted. Is there any way in Android Studio Profiler to identify which part of the code is initiating those threads, and is there any way to terminate them?

I have verified there are no memory leaks which are leaving these threads not collected by GC.

Here is the screenshot for the android studio profiler with the threads: Android Studio Profiler

3
  • You can place (conditional) breakpoints on the Thread constructors.
    – Robert
    Commented May 22 at 9:07
  • Okay, But the thread I am talking about comes from Internal elements of GooglePlaces API, how can I do this to them? @Robert Commented May 22 at 12:26
  • A thread is a Thread, no matter which library it creates. Therefore if you debug your app and place a breakpoint on the Thread constructors the code will stop at the breakpoint no matter who has created the thread and you can see by the stack trace who has created the thread.
    – Robert
    Commented May 22 at 12:37

1 Answer 1

0

I got the answer. The PlacesClient used by the Places API spawns 10 threads every time the plugin gets reloaded. These are internal threads created by the PlacesClient. Therefore, it is crucial to initialize the PlacesClient exactly once when using the Google Places API. Instantiating it multiple times will result in resource congestion and the creation of new threads (almost 10 on each initialization), which are never collected if the app is running continuously in the background. The application I am working on uses foreground services to run continuously in the background, preventing the GC from collecting the threads spawned by PlacesClient. However, all other threads are successfully garbage collected.

Not the answer you're looking for? Browse other questions tagged or ask your own question.