No, that's only a partial (and indeed very incomplete) solution. It relies on the Java GC knowing that that particular reference to the Haskell StablePtr is the only one that matters, and vice-versa for the Haskell GC.
So you want StablePtrs to contain a reference count, a new function to increment the count and for freeStablePtr to decrement the count?
We toyed with designs like that but always found other ways to achieve the same goal - but it's easy enough to do.
A variant is for newStablePtr to look for an existing StablePtr to the same thing. We avoided this design because of the semantic issues in testing Haskell pointers for equality but mostly to avoid imposing a lookup cost that we'd rarely benefit from.
GHC's StablePtr implementation does all this, BTW. We were considering removing it because of the overhead, though. Cheers, Simon