Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak #667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix memory leak #667

wants to merge 1 commit into from

Conversation

dr0i
Copy link
Member

@dr0i dr0i commented Feb 10, 2025

Let maps implement Closeable.

Fixes #666.

Let maps implement Closeable.
Copy link
Member

@blackwinter blackwinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It's probably worth mentioning that implementing Closeable only helps because both Metafix and Metamorph treat those resources specially by closing them when the stream gets closed. Otherwise, just implementing the interface wouldn't do anything.
  2. Not all maps are actually closable or should be forced to pretend to be. We should let each map implementation decide for itself (cf. SqlMap and JndiSqlMap).
  3. If you're implementing Closeable, you may also want to implement AutoCloseable as well.

@dr0i
Copy link
Member Author

dr0i commented Feb 11, 2025

  1. right. These maps are all functions of Metafix and Metamorph and are not used standalone, I think.
  2. I don't understand what you want to say. SqlMap and JndiSqlMap already do implement Closeable, so why not just make the need to implement mandatory when extending AbstractReadOnlyMap? You could always just "//do nothing" for close() (but are forced to make this decision deliberately)
  3. As I understand it AutoCloseable could break a contract of users that rely on close() to only throw an IOException and not all (checked) Exceptions (which could be thrown when using AutoCloseable). So while this could be nice for some this should be considered an API break IMO.

@blackwinter
Copy link
Member

  1. These maps are all functions of Metafix and Metamorph and are not used standalone, I think.

Well, but they can be (and are) used standalone. I don't think we should dismiss this option offhand.

  1. so why not just make the need to implement mandatory when extending AbstractReadOnlyMap?

Because not all maps have to be closable. It's not a property of AbstractReadOnlyMap, IMO.

  1. As I understand it AutoCloseable could break a contract of users that rely on close() to only throw an IOException and not all (checked) Exceptions (which could be thrown when using AutoCloseable).

I have to admit, I don't understand this part. Where would the API break be if the maps don't even implement close() yet?

But please note that these were only suggestions. If you're not persuaded, feel free to ignore. Just one thing, though: Maps that only implement close() in order to satisfy the interface should maybe include a comment like "Nothing to do" (cf. JndiSqlMap); just to be clear that there's actually nothing to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review
Development

Successfully merging this pull request may close these issues.

Memory leak through missing Closeable
2 participants