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

Limit memory usage scope #3084

Closed
maxonfjvipon opened this issue Apr 12, 2024 · 4 comments · Fixed by #3133
Closed

Limit memory usage scope #3084

maxonfjvipon opened this issue Apr 12, 2024 · 4 comments · Fixed by #3133

Comments

@maxonfjvipon
Copy link
Member

Current implementation of memory object leads to potential memory leaks because we except end-user to free allocated memory block. Of course user may just forget to do it. It's called "Hello, C++".
We should limit the scope of memory usage and free allocated memory automatically when scope is ended.
We can do using abstract objects:

(memory 0).alloc > mem
  [m] # here m is memory itself
    seq > @
      *
        m.write 42
        m.write (m.plus 1)
        m.read 

When abstract object finishes its execution, memory is freed automatically

@maxonfjvipon
Copy link
Member Author

@yegor256 check this out:

# Test.
[] > writes-into-memory
  memory > mem
    0
    [m]
      seq > @
        *
          m.write 10
          # do something else
  mem.eq 10 > @ # true

What do you think if this abstract object (I called it scope) would return last data written into memory? So
memory dataizes scope, reads last written data, frees memory and return the data.

@yegor256
Copy link
Member

@maxonfjvipon sounds good

@yegor256
Copy link
Member

yegor256 commented Apr 23, 2024

@maxonfjvipon I believe, this change deserves a blog post (and a new minor release)

@maxonfjvipon
Copy link
Member Author

@yegor256 let's make a new release with tag 0.36.1

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

Successfully merging a pull request may close this issue.

2 participants