Skip to content

property objects clean up #5

@Siqsuruq

Description

@Siqsuruq

Hello,I've tried to ask a question in mailing list but it looks like its offline so I have a question about cleaning up property objects. Here is an example, class A has object bObj as property, when i destroy aObj, should bObj be destroyed too? Right?

package require nx

 nx::Class create A {
 :property {bObj:object,type=B,substdefault {[B new]}}

 :method init {} {
 }
 }

 nx::Class create B {
 :method init {} {
 :hello
 }

 :public method hello {} {
 puts "Hello from bObj: [current object] of [[current object] info class] class."
 }
 }

 # Create aObj
 set a [A new]
 # Checking instances of B
 puts "Instances of B class: [B info instances]"
 # Destroing aObj and check instances of B
 $a destroy
 puts "Instances of B class after aObj destroyed: [B info instances]"

Question number 2. When i do set :bObj [B new] old bObj should be replaced?

    package require nx

    nx::Class create A {
    :property {bObj:object,type=B,substdefault {[B new]}}

    :method init {} {
    set :bObj [B new]
    }
    }

    nx::Class create B {
    :method init {} {
    :hello
    }

    :public method hello {} {
    puts "Hello from bObj: [current object] of [[current object] info class] class."
    }
    }

    # Create aObj
    set a [A new]
    # Checking instances of B
    puts "Instances of B class: [B info instances]"
    # Destroing aObj and check instances of B
    $a destroy
    puts "Instances of B class after aObj destroyed: [B info instances]"

Or maybe I do smth wrong? What is the correct way to clean up after an object is destroyed? Even if I create a custom destroy method and do ${:bObj} destroy one of them will still be in memory. Thank you.

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