55import org .labkey .api .data .ContainerManager ;
66import org .labkey .api .ldk .ExtendedSimpleModule ;
77import org .labkey .api .module .Module ;
8+ import org .labkey .api .module .ModuleContext ;
89import org .labkey .api .module .ModuleLoader ;
910import org .labkey .api .query .DefaultSchema ;
1011import org .labkey .api .query .QuerySchema ;
1718import java .util .Set ;
1819
1920public class GoogleDriveModule extends ExtendedSimpleModule {
20- @ Override
21- public boolean hasScripts () {
22- return true ;
23- }
24-
2521 @ Override
2622 @ NotNull
2723 protected Collection <WebPartFactory > createWebPartFactories () {
@@ -33,17 +29,23 @@ protected void init() {
3329 addController (GoogleDriveController .NAME , GoogleDriveController .class );
3430
3531 GoogleDriveService .set (new GoogleDriveServiceImpl ());
32+ }
3633
37- Module thisModule = ModuleLoader .getInstance ().getModule (GoogleDriveModule .class );
34+ @ Override
35+ protected void doStartupAfterSpringConfig (ModuleContext moduleContext )
36+ {
37+ // We moved this from init() to startup() because init() is too early to be referencing active modules, which
38+ // indirectly loads and stashes web parts. Some referenced modules might be removed after this module's init()
39+ // runs (e.g., if dependencies are missing), which would then lead to memory leaks.
3840 Container home = ContainerManager .getHomeContainer ();
3941
4042 // Ensure that we're enabled in the home module, since we'll use that for our queries.
4143 if (ModuleLoader .getInstance ().shouldInsertData ())
4244 {
4345 Set <Module > homeModules = new HashSet <>(home .getActiveModules ());
44- if (!homeModules .contains (thisModule ))
46+ if (!homeModules .contains (this ))
4547 {
46- homeModules .add (thisModule );
48+ homeModules .add (this );
4749 home .setActiveModules (homeModules );
4850 }
4951 }
@@ -66,7 +68,7 @@ public void registerSchemas() {
6668 DefaultSchema .registerProvider (GoogleDriveSchema .NAME , new DefaultSchema .SchemaProvider (this ) {
6769 @ Override
6870 public QuerySchema createSchema (final DefaultSchema schema , Module module ) {
69- return ( QuerySchema ) new GoogleDriveSchema (schema .getUser (), schema .getContainer ());
71+ return new GoogleDriveSchema (schema .getUser (), schema .getContainer ());
7072 }
7173 });
7274 }
0 commit comments