Quantcast
Channel: Should we avoid object creation in Java? - Software Engineering Stack Exchange
Browsing all 15 articles
Browse latest View live

Answer by user321630 for Should we avoid object creation in Java?

Java's GC is actually very optimized in terms of creating lots of objects rapidly in a "burst" fashion. From what I can understand they use a sequential allocator (fastest and simplest O(1) allocator...

View Article



Answer by Archimedes Trajano for Should we avoid object creation in Java?

I did a quick microbenchmark regarding this and I have provided full sources in github. My conclusion is that whether creating objects is expensive or not is not the issue, but continuously creating...

View Article

Answer by Anthony Ananich for Should we avoid object creation in Java?

Joshua Bloch (one of Java platform creators) wrote in his book Effective Java in 2001:Avoiding object creation by maintaining your own object pool is a bad idea unless the objects in the pool are...

View Article

Answer by AKS for Should we avoid object creation in Java?

I think your colleague must have said from the perspective of unnecessary object creation.I mean if you are creating the same object frequently then it is better to share that object.Even in cases...

View Article

Answer by rkj for Should we avoid object creation in Java?

As people have said object creation is not a big cost in Java (but I bet bigger than most simple operations like adding, etc) and you shouldn't avoid it too much.That said it still a cost, and...

View Article


Answer by Alex for Should we avoid object creation in Java?

There's more to creating a class than allocating memory.There's also initialization, I'm not sure why that part is not covered by all the answers.Normal classes contain some variables, and do some form...

View Article

Answer by mikera for Should we avoid object creation in Java?

Other posters have rightly pointed out that object creation is extremely fast in Java, and that you should not usually worry about it in any normal Java application.There are a couple of very special...

View Article

Answer by ratchet freak for Should we avoid object creation in Java?

the GC is tuned for many short lived objectthat said if you can trivially reduce object allocation you should one example would be building a string in a loop, the naive way would beString str =...

View Article


Answer by Peter Kelly for Should we avoid object creation in Java?

There is one case where you may be discouraged from creating too many objects in Java because of the overhead - designing for performance on the Android platformOther than that, the above answers hold...

View Article


Answer by greg for Should we avoid object creation in Java?

There is a kernel of truth in what your colleague is saying. I respectfully suggest the issue with object creation is actually garbage collection. In C++ the programmer can control precisely how memory...

View Article

Answer by jasonk for Should we avoid object creation in Java?

Bottom line:Don't compromise your design in order to take shortcuts creating objects. Do avoid creating objects unnecessarily. If sensible, design to avoid redundant operations (of any sort).Contrary...

View Article

Answer by user7519 for Should we avoid object creation in Java?

Your colleague has no idea what they are talking about.Your most expensive operation would be listening to them. They wasted your time mis-directing you to information that is over a decade out of date...

View Article

Answer by amara for Should we avoid object creation in Java?

Actually, due to the memory management strategies that the Java language (or any other managed language) makes possible, object creation is little more than incrementing a pointer in a block of memory...

View Article


Answer by Oleksi for Should we avoid object creation in Java?

This really depends on the specific application, so it's really hard to say in general. However, I would be pretty surprised if object creation was actually a performance bottleneck in an application....

View Article

Should we avoid object creation in Java?

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible.This seems somewhat to defeat the...

View Article

Browsing all 15 articles
Browse latest View live




Latest Images