codeape Posted October 28, 2014 Share Posted October 28, 2014 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. Quote Link to comment Share on other sites More sharing options...
Guppy Posted October 28, 2014 Share Posted October 28, 2014 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. Quote 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 More sharing options...
codeape Posted October 28, 2014 Author Share Posted October 28, 2014 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? Quote Link to comment Share on other sites More sharing options...
Guppy Posted October 28, 2014 Share Posted October 28, 2014 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. Quote 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 More sharing options...
codeape Posted October 28, 2014 Author Share Posted October 28, 2014 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. Yes of course ... but I am a tidy person Quote Link to comment Share on other sites More sharing options...
Josh Posted October 28, 2014 Share Posted October 28, 2014 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. Quote 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 More sharing options...
codeape Posted October 28, 2014 Author Share Posted October 28, 2014 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted October 29, 2014 Share Posted October 29, 2014 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. 1 Quote 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 More sharing options...
codeape Posted October 29, 2014 Author Share Posted October 29, 2014 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.