Visitar URL original
Memory.dispose() does not remove "this" from the allocatedMemory map · Issue #697 · java-native-access/jna · GitHub
Skip to content

Memory.dispose() does not remove "this" from the allocatedMemory map #697

Closed

Description

@AgnetaWalterscheidt

Method Memory.dispose() frees the peer and sets it to 0. Afterwards it calls allocatedMemory.remove(this). This call does not find the Memory in the map: Memory is a subclass of Pointer which uses the peer for hashcode() and equals() and therefore "this" is no longer equal to the Memory that was put in the map.
This bug is easy to fix by first calling allocatedMemory.remove(this) and then setting the peer to 0.

Activity

  1. twall commented on Aug 30, 2016

    @twall
    Contributor

    Good catch. Could you provide a PR with the fix and an associated test?

    On Tue, Aug 30, 2016 at 3:33 AM, AgnetaWalterscheidt <
    notifications@github.com> wrote:

    Method Memory.dispose() frees the peer and sets it to 0. Afterwards it
    calls allocatedMemory.remove(this). This call does not find the Memory in
    the map: Memory is a subclass of Pointer which uses the peer for hashcode()
    and equals() and therefore "this" is no longer equal to the Memory that was
    put in the map.
    This bug is easy to fix by first calling allocatedMemory.remove(this) and
    then setting the peer to 0.

    —
    You are receiving this because you are subscribed to this thread.
    Reply to this email directly, view it on GitHub
    #697, or mute the thread
    https://github.com/notifications/unsubscribe-auth/AAuMrTUjJYafXGniw4wqiEDHC1hud0XGks5qk9y0gaJpZM4JwOmU
    .

  2. added a commit that references this issue on Oct 10, 2016
    b31240f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions