Jump to content

Counting all the references


codeape
 Share

Recommended Posts

I understand the concept of reference counting and I have read this:

http://www.leadwerks.com/werkspace/page/documentation/_/user-guide/getting-started/reference-counting-r613

 

As I understand it I can get the total amount of references to a Leadwerks::Object sub-class instance by doing this (C++):

shader = material->GetShader();
int count = shader->GetRefCount()

 

My question is if it is possible to get the total amount of references for all instances of Leadwerks::Object and sub-classes. I want to print it right before I exit my game so that I know that all my resources has been released (avoid memory leaks).

 

Thanks for any help in advance.

Link to comment
Share on other sites

Why do you want to count references - if your looking for leaks surely instances are what's interesting?

 

I mean you could potentially have lots of pointers pointing to a free()'ed instance and that wouldn't indicate a leak.

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

Why do you want to count references - if your looking for leaks surely instances are what's interesting?

 

I mean you could potentially have lots of pointers pointing to a free()'ed instance and that wouldn't indicate a leak.

 

If I do not do shader->Release() but have done shader->AddRef(), wouldn't I get a memory leak? Isn't the point that when shader->Release() make the ref count go to 0 the Leadwerks::Object sub-class freed?

 

Have I misunderstood Leadwerks ref count completely?

Link to comment
Share on other sites

If I do not do shader->Release() but have done shader->AddRef(), wouldn't I get a memory leak? Isn't the point that when shader->Release() make the ref count go to 0 the Leadwerks::Object sub-class freed?

 

Have I misunderstood Leadwerks ref count completely?

 

It gets automatically freed when there are 0 refs, but you can free it manually before this.

Eg. I imagine that the engine will free entities when unloading the map that spawned them regardless of ref count.

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

Everything in Leadwerks is derived from the Object class...The graphics and physics modules, math classes like Vec3's, everything. So getting your summary ref count down to zero is just about impossible.

 

There is no "total" ref count kept of all objects.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Everything in Leadwerks is derived from the Object class...The graphics and physics modules, math classes like Vec3's, everything. So getting your summary ref count down to zero is just about impossible.

 

There is no "total" ref count kept of all objects.

 

Thnx, got it.

 

Another question about reference counting. If I do like this:

 

class A {
...
Shader aShader1 = Shader::Load("shaders/my.shader")
...
}
...
class B {
...
Shader sameShade = Shader::Load("shaders/my.shader")
...
}

 

Will this result in a ref count of 2 for the same instace of a Shader instance using "shaders/my.shader" or will this result in 2 instances of Shader with a refcount of 1 each. I can not find any info about that in the doc.

 

Thank you again.

Link to comment
Share on other sites

The truth is, there's no such thing as instances. When you call Shader::Load() the second time, it just returns the original and increments the ref count. So the shaders ref count at that point would be 2.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

The truth is, there's no such thing as instances. When you call Shader::Load() the second time, it just returns the original and increments the ref count. So the shaders ref count at that point would be 2.

 

Very nice indeed. Thank you for all the help guys biggrin.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...