Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Class hierarchy prolem
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="dgront, post: 3437993"] I have a class, say MyClass, that consist of a few fields in particular of a list of other objects: public MyClass { int someID; LinkedList<ManyOfThem> bigData; } public ManyOfThem { // many fields inside } I read a file and I create MyClass object from it. My structure of objects reflects the file format. For each file I calculate some features: public MyFeature { double theFeatureValue; MyClass source; } As you see, I keep the computed value and a reference to MyClass because I need to remember MyClass.someID for some reasons. Unfortunately Java also keeps in memory all ManyOfThem objects and there are really many of them! Unfortunately ManyOfThem objects are necessary to calculate MyFeature. The problem: I read many files and for each I compute just a few MyFeature features. Each MyFeature has a reference to MyClass. Because MyClass keeps also a list of ManyOfThem references, 2GB RAM is not enough to parse my all data. MyFeature data itself is very small, the problem is how to get rid of ManyOfThem objects. In C++ I would use destructor.... What to do in Java to forget about ManyOfThem objects? Can I do the following: I split MyClass into two: public SimplerClass { int someID; } public MyClass extends SimplerClass { LinkedList<ManyOfThem> bigData; } And now MyFeature keeps only a reference to the simpler class. public MyFeature { double theFeatureValue; SimplerClass source; } I guess when I set "source" field to a reference to (SimplerClass) MyClass. It want solve my problem, will it? But what if I set: someFeature.source = ((SimplerClass) myClassObject).clone() I expect that clone() method from SimplerClass will create a new object without ManyOfThem stuff. And myClass memory will be free at some point. Is it correct? Do you know any simpler/other solution to my problem? SIncerely yours, Dominik [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Class hierarchy prolem
Top