This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is call to reset() needed?  RSS feed

 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Im serialising java objects to file using ObjectOutputStream. They are all unique objects so i'm using writeUnshared() and then resetting the stream say every 10K elements. From reading the API & sun code, it looks like writeUnshared() never caches references so i'm wondering do I need to bother calling reset at all? I don't think so, but i'm just worried about memory consumption IF the stream still saves the references when using writeUnshared(which it sounds like it doesn't). Can anyone confirm the behaviour?

Thanks
/Tom
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does look like that's correct, and reset() is not really needed here. However thhere doesn't seem to be a strict guarantee of that in the API, so it's possible that some implementations (past or future) may do it a bit differently. So I would think it's not a bad idea to call reset() periodically anyway, just to be safe. It shouldn't be necessary, but provides an extra sense of security. Unless you observe that this takes too much time (which seems unlikely, but possible). I hadn't previously noticed these two methods in OSS, so I'm glad I read this post.
 
Tom Johnson
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the reply. Thats what I was thinking too, if im writing ~70K objects out and resetting every 10K, thats only 7 calls to reset so it should be minimal compared to overall time

/Tom
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!