Skip to content

Commit 70a9e8b

Browse files
committed
Fix module memory leaks caused by GoogleDriveModule
1 parent c511fab commit 70a9e8b

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

GoogleDrive/src/org/labkey/googledrive/GoogleDriveModule.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.labkey.api.data.ContainerManager;
66
import org.labkey.api.ldk.ExtendedSimpleModule;
77
import org.labkey.api.module.Module;
8+
import org.labkey.api.module.ModuleContext;
89
import org.labkey.api.module.ModuleLoader;
910
import org.labkey.api.query.DefaultSchema;
1011
import org.labkey.api.query.QuerySchema;
@@ -17,11 +18,6 @@
1718
import java.util.Set;
1819

1920
public 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
}

WNPRC_r24/src/org/labkey/wnprc_r24/wnprc_r24Module.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public void doStartup(ModuleContext moduleContext)
7979
final DbSchema dbSchema = DbSchema.get(schemaName, DbSchemaType.Module);
8080
DefaultSchema.registerProvider(dbSchema.getQuerySchemaName(), new DefaultSchema.SchemaProvider(this)
8181
{
82+
@Override
8283
public QuerySchema createSchema(final DefaultSchema schema, Module module)
8384
{
8485
DbSchema dbSchema = DbSchema.get(schemaName, DbSchemaType.Module);

WNPRC_u24/src/org/labkey/wnprc_u24/wnprc_u24Module.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public void doStartup(ModuleContext moduleContext)
7979
final DbSchema dbSchema = DbSchema.get(schemaName, DbSchemaType.Module);
8080
DefaultSchema.registerProvider(dbSchema.getQuerySchemaName(), new DefaultSchema.SchemaProvider(this)
8181
{
82+
@Override
8283
public QuerySchema createSchema(final DefaultSchema schema, Module module)
8384
{
8485
DbSchema dbSchema = DbSchema.get(schemaName, DbSchemaType.Module);

0 commit comments

Comments
 (0)