Giter Club home page Giter Club logo

Comments (12)

SeanTAllen avatar SeanTAllen commented on May 29, 2024 1

@mfelsche can you highlight the "you can detect the repetition in pointer values" to make sure what you mean is the same as what others looking at the stack would also mean?

from ponyc.

SeanTAllen avatar SeanTAllen commented on May 29, 2024

Can you clarify "anymore" and when specifically in terms of pony version this arose?

from ponyc.

SeanTAllen avatar SeanTAllen commented on May 29, 2024

Do you have a minimal example that is runnable by others? The smaller example does not compile so its impossible to debug.

from ponyc.

mfelsche avatar mfelsche commented on May 29, 2024

The ponyc version is the current tip of the main branch: commit 4ec27c827ab32d73937db198bfcae4be4733dcef. Didnt try on older versions yet.

Sorry for the bad reproducer, i fixed it to compile. Typo on my end.

After the create_reference_cycle behavior is done executing, the runtime seems to be stuck in doing gc.

from ponyc.

SeanTAllen avatar SeanTAllen commented on May 29, 2024

This issue exists in pony 0.50.0 so it is at least several months old. I took "anymore" to be "recently worked".

I'm going to edit the original comment.

from ponyc.

stefandd avatar stefandd commented on May 29, 2024

I don't think this is a bug, but rather expected behavior!

The code creates an endless loop inside a behavior. However, the runtime attempts GC cycles only at the end of behaviors. The code prevents this from ever happening since the loop variable j is never changed from its initial value 10. Therefore, the “run-away” memory allocation is bound to happen.

EDIT: This is also discussed here. What is done in the code is practically the same as the giant for loop in the example there...
https://tutorial.ponylang.io/gotchas/garbage-collection.html#long-running-behaviors-and-memory

from ponyc.

SeanTAllen avatar SeanTAllen commented on May 29, 2024

OMG, I can't believe I missed that. Thanks @stefandd. I'll do a test without the endless loop to verify all works as expected.

from ponyc.

stefandd avatar stefandd commented on May 29, 2024

@SeanTAllen I just tried it with if j > 0 then instead of while j > 0 do in the playground, and it finishes fine with Done

from ponyc.

SeanTAllen avatar SeanTAllen commented on May 29, 2024

Yeah I tried a variation on this as well with a timer and I don't see an indication of a leak. I can see that nodes are getting collected with variations on this program that have a _final on Node.

use "collections"
use "time"

class Node

  var parent: (Node | None) = None
  var child: (Node | None) = None

  new ref create() => None

actor Main
  let _timers: Timers
  var ast: (Node | None) = None

  be create_reference_cycle() =>
    let root = Node
    let child = Node
    child.parent = root

    // add children pointing back at parent
    var j: USize = 10
    var up = child
    while j > 0 do
      let down = Node
      down.parent = up
      up = down
      j = j - 1
    end
    ast = root

  new create(env: Env) =>
    _timers = Timers
    let timer = Timer(Notify(this), 5_000, 2_000)
    _timers(consume timer)

  class Notify is TimerNotify
    let _main: Main

    new iso create(main: Main) =>
      _main = main

    fun ref apply(timer: Timer, count: U64): Bool =>
      _main.create_reference_cycle()
      true

from ponyc.

mfelsche avatar mfelsche commented on May 29, 2024

Sorry for the bad reproducer.

But I have definitely seen this behaviour in the wild with ponyc 0.53. I came across it when modelling the ponyc ast_t type as a struct AST in pony with the parent and child pointers being NullablePointer[AST]. The ast_t/AST was created by libponyc and then returned as a plain AST struct. It was creating trouble when the gc kicked in.

I worked around it by not modelling the ast_t as a pony struct at all. I will try to find a simple reproducer for this with structs. And check again if it reproduces in the first place. Will reopen if so.

from ponyc.

stefandd avatar stefandd commented on May 29, 2024

@mfelsche Just curious - does this mean that are in essence two versions of the Pony GC running concurrently in your use case? (the one in your Pony program and the one in the wrapped libponyc) I wonder if GC troubles stem from such linked objects being traced by two GC instances?

from ponyc.

SeanTAllen avatar SeanTAllen commented on May 29, 2024

No. There wouldn't be two versions of the garbage collector.

from ponyc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.