Comments (2)
Following is a transcript from a chat I had with Katy about memory management for Model objects. I have decided to pursue manual memory management for model objects.
1:29 PM
me: I've been working on implementing the use of intrusive_ptr for memory management of models and have run into some issues...
1:30 PM
Katy: ok..
me: Because of the tight integration of Message and Model class (via transactions) there is a great deal of casting between Model* and Communicator* (and vice versa)
1:31 PM
This makes memory management via smart pointers very difficult because Model doesn't inherit from Communicator (or vice versa).
So we are basically casting between parallely inherited classes.
Katy: the model class shouldn't hold the transactions stuff.. only the communicator class should.
1:32 PM
me: the model class doesn't hold any transactions stuff.
Katy: so then, your problem "Because of the tight integration of Message and Model class (via transactions) " is a little confusing for me..
me: sorry
1:33 PM
message class has methods that accept/return both communicator and model pointers.
1:34 PM
and uses both in its implementation because of the interior Transaction struct.
I just had an idea - thanks for being a sound board.
17 minutes
1:51 PM
me: In order for us to effectively reference count concrete models, they can only have one reference count instance variable. So I can't put a separate instance var for ref counting in both the message and communicator classes - which is the only solution I could come up with - because then we would have two separate ref counts for each object. The real solution I can think of is basically to have the Model class absorb the Communicator class.
1:53 PM
thoughts
?
1:55 PM
Katy: hm.
I think I'm understanding your problem.
The model class pointers in the transactions should just be communicator pointers, then.
1:56 PM
me: There was a need to use intrusive pointers because of the leaking of the this pointer.
- yes but
Katy: so too with the methods that return models
me: they WILL need to be casted to model pointers eventually anyway
Katy: that's fine.
oh.
it's not.
right.
1:57 PM
you'll have the same problem with time agent's wont you?
me: I don't think so...
I'd have to think about it.
1:59 PM
Katy: I don't really like the idea of the model class absorbing the communicator class.
... but i can see why that's the solution you're coming to.
2:01 PM
me: The time agent interface is only every used by the timer - but yes it would also be a problem.
Because the idea with smart pointers is if you don't use them everywhere, then you are going to get segfaults.
2:03 PM
I can think of some nasty round about solutions - but having the model class absorb communicator class is still the most elegant by far. The communicator class is only 2 virtual/abstract methods anyway.
2:05 PM
I don't think I like multiple inheritance anymore.
Katy: hm. i can see why it feels that way... but ...
you know it solves so many other ills.
i'm sure there's a good solution. keep googling? maybe talk to paul?
2:06 PM
his research office hours might have just ended, but I'm sure you could grab him...
me: k
Katy: steve would know too.
actually
me: going to check now
Katy: being a c++ genius, steve is always my go-to man.
2:07 PM
me: they are both gone
Katy: bummer.
you can probably grab steve via email.
2:08 PM
it's worth thinking through, so I'm sure a full solution can wait until monday in the worst case.
good luck!
51 minutes
3:00 PM
me: I talked with steve - the only case where an object inherits from model but not communicator is converters.
We could easily make Model class just inherit from Communicator.
But...
3:01 PM
As far as memory management goes - my discussion with steve has shifted me toward using a manual managment strategy for Models. For messages and resource objects though, smart pointers are the better solution.
from cyclus.
See f730223 for a first stab at this. Basically each model owns its children and is responsible for deallocating/deleting them. The remaining issues that needs to be addressed in some fashion:
- preventing previously sent messages from returning (or attempting to return) to a deleted sender (addressed in commit 1fb7d38).
- allowing models to be properly book-kept even after a model has been deallocated/deleted (addressed in commit 905498d)
- making all destructors virtual - this will allow objects to be properly deleted even though all we might have of them is an upcasted pointer (addressed in commit 2bc9e8d)
- bug introduced in f730223 - model dealloc of children doesn't account for list being modified during iteration (addressed in commit 1ac5fdb)
from cyclus.
Related Issues (20)
- cyclus_unit_tests error!! HOT 1
- Brew install instruction
- Introduce canonical definition of large & small constants
- https://fuelcycle.org/user/writing_input.rst does not work
- Linking error when using conda HOT 2
- MacOS: Homebrew + libxml2
- cyclus-build-deps in need of update HOT 5
- For windows users (additional info I found super helpful) HOT 2
- http://fuelcycle.org/arche/tutorial/index.html does not open HOT 3
- Switch to GithubAction for CI
- RHEL unable to install due to libxml++-2.6 HOT 3
- I failed to install cyclus successfully.Please help me. HOT 4
- How do I set the type of reactor? HOT 1
- Is there a more detailed tutorial? HOT 1
- Install Failure with Ubunutu VM on WIndows HOT 1
- Unable to complete installation Ubunutu VM on windows. HOT 1
- Resolve BOOST deprecated messages
- Update CMake version compatibility HOT 1
- Include git as a dependency when installing from tarball
- Update dependencies to allow coupling with Dakota HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cyclus.