-1

As I know, Java does not have any method for managing memory, because the whole memory management is done by the built in automatically running garbage collector, which might be a little bit inefficient in some cases.

http://www.coralblocks.com/

I have found this website, which tells that they are making a java tools and libraries which works without making any garbage at all. I would like to get some kind of logical explanation about how could it be possible.

gyurix
  • 1,106
  • 9
  • 23
  • Please share any specific problem if you have.. – Narain Mittal May 03 '16 at 22:24
  • 3
    Yes. That's called marketing. Count the number of buzz-words. – Tunaki May 03 '16 at 22:24
  • 2
    Your question isn't a bad one (they are making a quite outrageous claim after all) but it doesn't belong here. Perhaps programmers.se might be more appropriate. – Jeroen Vannevel May 03 '16 at 22:26
  • 2
    @Tunaki but it's "zero garbage" marketing... – Boris the Spider May 03 '16 at 22:28
  • 1
    You already nailed it, the memory management “might be a *little bit* inefficient in *some cases*”. Now consider that algorithms trying to avoid garbage at all cost “might be even more inefficient in even more cases”. – Holger May 04 '16 at 15:09
  • @Holger Yes, it might be but it might also significantly improve the applications performance if the avoid GC operations are coded correctly – gyurix May 04 '16 at 17:22
  • 1
    @gyurix: that’s a myth made two decades ago. Avoiding garbage at all costs implies performing your own kind of memory management and if your doing it right, you may be on par with the built-in memory manager, but there is no reason why your custom memory management should be better. First of all, garbage doesn’t imply costs per se. The actual cost is the amount of the average *remaining* objects (which have to be traversed and copied to the survivor space) multiplied with the number of cycles. Producing lots of garbage could trigger lots of cycles at no cost, if there are no remaining objects. – Holger May 04 '16 at 17:36

4 Answers4

5

http://www.coralblocks.com/index.php/2015/10/is-coralfix-the-fastest-and-easiest-to-use-fix-engine/

All Coral Blocks components produce zero garbage for the GC in the critical path.

My guess. Pre-allocated buffers, no String objects. As they say:

At Coral Blocks we use Java as a syntax language. Our libraries have zero external dependencies and we don’t even rely on the JDK standard libraries. With CoralFIX you have total control over the critical path.

Andreas
  • 154,647
  • 11
  • 152
  • 247
4

It's not possible to completely cease creating garbage, and it's premature to try to optimize out garbage creation except for certain specific tasks and on extremely memory constrained systems. A great deal of tasks will cause allocations of some sort.

However, garbage can be decreased but not eliminated by:

  • Pooling and re-using some object references.
  • Allocating large blocks of data off-heap and managing them manually.
nanofarad
  • 40,330
  • 4
  • 86
  • 117
4

In fact, the article about CoralFIX says:

Zero Garbage: All Coral Blocks components produce zero garbage for the GC in the critical path.

That's not the same as saying zero garbage at all. And it is achievable (for Coral) only in a relatively small class of applications; i.e. message-based systems where you can do all of the work by in-place matching on the bytes in a message buffer. As soon as you need to need to use normal data structures or (most) standard library classes you will be generating objects.

And ...

At Coral Blocks we use Java as a syntax language.

In other words, Coral Blocks application programmers don't write Java code!


Is it possible to write your code to do the same thing?

In theory Yes, but in practice probably No. You would need to replace so much of the functionality of the Java SE libraries (and 3rd party libraries) that you would be better off writing your application1 in a different programming language.

1 - I guess, if your application was simple and had minimal Java SE and external library dependencies, then it would be feasible to do it. But few non-trivial applications are like that.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • They claim in their website they have developed complex trading algos, a FIX engine and high-performance http servers that are garbage-free. It looks like they are using [CoralBits](http://www.coralblocks.com/index.php/category/coralbits/) instead of the JDK standard libraries or any other 3rd party lib that produces garbage. – TakeSoUp Dec 09 '16 at 15:24
2

You can't avoid making garbage in java, you can reduce it though. Good and efficient code usually doesn't leave any variables without use. The one way you can avoid making garbage is by paying attention to what you leave unused.

CodeDon
  • 38
  • 7