Commits

Matt Knepley committed a546ed6

DM: During DMDestroy(), clear out known compositions to avoid circular ref
- These come from FS

Comments (5)

  1. Jed Brown

    I know this is late, but I didn't notice it when it was committed. I think this is wrong because you'll lose the association if someone gets a hold of the DM and does something that should be benign like KSPCreate(comm,&ksp); KSPSetDM(ksp,dm); KSPDestroy(&ksp);. I think that whoever composes these attributes needs to do it some other way, so that they don't create a circular reference.

    1. Matt Knepley author

      The circular ref is not like that. and this change does not change any PETSc semantics. The circularity is two stage, and happens everywhere once you have DMs in Vec. I sm not sure why you would have a problem with this change.

        1. Matt Knepley author

          Okay, I agree, but I am not sure we can naively count 1 for each attached space. This is one more reason to hate attachment over an explicit API. Should we get rid of attachment here?

Files changed (1)

src/dm/interface/dm.c

   if (!*dm) PetscFunctionReturn(0);
   PetscValidHeaderSpecific((*dm),DM_CLASSID,1);
 
+  /* I think it makes sense to dump all attached things when you are destroyed, which also eliminates circular references */
+  for (f = 0; f < (*dm)->numFields; ++f) {
+    ierr = PetscObjectCompose((*dm)->fields[f], "pmat", NULL);CHKERRQ(ierr);
+    ierr = PetscObjectCompose((*dm)->fields[f], "nullspace", NULL);CHKERRQ(ierr);
+    ierr = PetscObjectCompose((*dm)->fields[f], "nearnullspace", NULL);CHKERRQ(ierr);
+  }
   /* count all the circular references of DM and its contained Vecs */
   for (i=0; i<DM_MAX_WORK_VECTORS; i++) {
     if ((*dm)->localin[i])  cnt++;