Giter Site home page Giter Site logo

Comments (8)

prpr19xx avatar prpr19xx commented on June 12, 2024

This is even simpler:

package require oo

class t { val 0 }
t method setval {v} { set val $v }

proc final {ref value} { puts "Destroy $ref" }

set l1 [list 99 96 98]
set entries [lmap i $l1 {
        set tt [t new]
        finalize $tt final
        puts "Create $tt"
        $tt setval $i
        list $tt
    }]
puts "Collect A"
collect
puts "Display"
set e [lindex $entries 1]
puts $e
puts [$e classname]
puts "Collect B"
collect

and generates this (with a slight mod. to the GC debugging to show refCount):

Create ::<reference.<t______>.00000000000000000000>
Create ::<reference.<t______>.00000000000000000002>
Create ::<reference.<t______>.00000000000000000004>
Collect A
MARK: 4 (type=command) refCount=3
MARK: 2 (type=command) refCount=2
MARK: 0 (type=command) refCount=2
Display
::<reference.<t______>.00000000000000000002>
t
Collect B
MARK: 4 (type=command) refCount=3
No MARK: 2 objPtr->refCount=2 - command with refcount=1
No MARK: 2 objPtr->refCount=1 - command with refcount=1
MARK: 0 (type=command) refCount=2
COLLECTING 2
Destroy <reference.<t______>.00000000000000000002>

It seems that reading any property of $e causes the problem, as it goes away if commented out.
Changing the value of the lindex index to 2 doesn't break it, but 0 and 1 do.
Not sure why object "4" has different refCount to the other two either, but probably explains the preceding sentence.

All this seems to have started on 5 Jun 2020 with 5d44077.

from jimtcl.

msteveb avatar msteveb commented on June 12, 2024

It does look like there is something not quite right there. I pushed a tentative fix to the branch garbage-collection-fix. Would you mind trying it out and let me know what you think?

from jimtcl.

prpr19xx avatar prpr19xx commented on June 12, 2024

The output is now not showing any destruction, which is good:

Create ::<reference.<t______>.00000000000000000000>
Create ::<reference.<t______>.00000000000000000002>
Create ::<reference.<t______>.00000000000000000004>
Collect A
MARK: 4 (type=command) refCount=3
MARK: 2 (type=command) refCount=2
MARK: 0 (type=command) refCount=2
Display
::<reference.<t______>.00000000000000000002>
t
Collect B
MARK: 4 (type=command) refCount=3
MARK: 2 (type=command) refCount=2
No MARK: 2 - command with refcount=1
MARK: 0 (type=command) refCount=2

Still not sure if the refCount stuff is correct as I don't understand it (I tried selected old versions, back to about 2011 until they wouldn't compile, and it's always done that), but certainly the big problem is apparently fixed.

from jimtcl.

msteveb avatar msteveb commented on June 12, 2024

Thanks. I'll try to come up with some unit tests that show both original problems before I merge it

from jimtcl.

prpr19xx avatar prpr19xx commented on June 12, 2024

Not sure why me merging this fix into my personal fork should have closed the issue in the upstream repository when it hasn't been committed to upstream master.

from jimtcl.

msteveb avatar msteveb commented on June 12, 2024

Sure. I don't know why either. I still want to create some unit tests to confirm that the fix is correct before I merge.

from jimtcl.

Mar181-arc avatar Mar181-arc commented on June 12, 2024

Code scanning - action

from jimtcl.

msteveb avatar msteveb commented on June 12, 2024

I believe I now have a better fix for this problem (garbage-collection-fix-take2) taking into account that there can be multiple objects that refer to the same reference. I think it will end up the same, but this approach makes more sense to me.

from jimtcl.

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.