Claude Code performance

Memory Overflow from String Concatenation in Loop

Processing large files or datasets causes out-of-memory errors. Profiling shows massive string accumulation. The issue: concatenating strings in a loop creates new string object each iteration.

Simple string concatenation is inefficient when done repeatedly.

Error Messages You Might See

java.lang.OutOfMemoryError: Java heap space Memory usage spikes when processing large data Application crashes with string concatenation

Common Causes

  1. Using += in loop to build strings: str += item creates new object each iteration
  2. String concatenation inside tight loop processing millions of items
  3. No buffer/accumulator, just repeatedly building larger strings
  4. Serialization to JSON or XML using simple string concatenation
  5. Log message building with repeated concatenation

How to Fix It

Use StringBuilder (Java) or StringBuffer for accumulation: StringBuilder sb = new StringBuilder(); sb.append(item). In loops: always use StringBuilder. For JSON: use library like Jackson, Gson. For logging: use parameterized messages: log.info("Item: {}", item) not "Item: " + item. Test with large data: if memory spikes, likely concatenation issue.

Real developers can help you.

Costea Adrian Costea Adrian Embedded Engineer specilizing in perception systems. Latest project was a adas camera calibration system. Krishna Sai Kuncha Krishna Sai Kuncha Experienced Professional Full stack Developer with 8+ years of experience across react, python, js, ts, golang and react-native. Developed inhouse websearch tooling for AI before websearch was solved : ) Franck Plazanet Franck Plazanet I am a Strategic Engineering Leader with over 8 years of experience building high-availability enterprise systems and scaling high-performing technical teams. My focus is on bridging the gap between complex technology and business growth. Core Expertise: 🚀 Leadership: Managing and coaching teams of 15+ engineers, fostering a culture of accountability and continuous improvement. 🏗️ Architecture: Enterprise Core Systems, Multi-system Integration (ERP/API/ETL), and Core Database Structure. ☁️ Cloud & Scale: AWS Expert; architected systems handling 10B+ monthly requests and managing 100k+ SKUs. 📈 Business Impact: Aligning tech strategy with P&L goals to drive $70k+ in monthly recurring revenue. I thrive on "out-of-the-box" thinking to solve complex technical bottlenecks and am always looking for ways to use automation to improve business productivity. Dor Yaloz Dor Yaloz SW engineer with 6+ years of experience, I worked with React/Node/Python did projects with React+Capacitor.js for ios Supabase expert Simon A. Simon A. I'm a backend developer building APIs, emulators, and interactive game systems. Professionally, I've developed Java/Spring reporting solutions, managed relational and NoSQL databases, and implemented CI/CD workflows. Matthew Butler Matthew Butler Systems Development Engineer @ Amazon Web Services Jen Jacobsen Jen Jacobsen I’m a Full-Stack Developer with over 10 years of experience building modern web and mobile applications. I enjoy working across the full product lifecycle — turning ideas into real, well-built products that are intuitive for users and scalable for businesses. I particularly enjoy building mobile apps, modern web platforms, and solving complex technical problems in a way that keeps systems clean, reliable, and easy to maintain. rayush33 rayush33 JavaScript (React.js, React Native, Node.js) Developer with demonstrated industry experience of 4+ years, actively looking for opportunities to hone my skills as well as help small-scale business owners with solutions to technical problems Prakash Prajapati Prakash Prajapati I’m a Senior Python Developer specializing in building secure, scalable, and highly available systems. I work primarily with Python, Django, FastAPI, Docker, PostgreSQL, and modern AI tooling such as PydanticAI, focusing on clean architecture, strong design principles, and reliable DevOps practices. I enjoy solving complex engineering problems and designing systems that are maintainable, resilient, and built to scale. Daniel Vázquez Daniel Vázquez Software Engineer with over 10 years of experience on Startups, Government, big tech industry & consulting.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

Why is += slow in loops?

Each += creates new String. For 1000 items: creates 1000 intermediate strings. StringBuilder creates 1 string.

How much faster is StringBuilder?

10-100x faster for 1000s of concatenations. Order of magnitude better for large datasets.

When should StringBuilder be used?

Always in loops. Even 10+ concatenations. Single concatenation outside loop is fine: str = a + b + c.

Related Claude Code Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help