Korean technology giant Samsung Electronics is cashing in on its memory chips. The boom may not last forever but its leading technology position should help it weather slower times well too.

The world’s largest smartphone and memory-chip maker said Thursday that its operating profit for the three months ended in June rose 54% from a year earlier to the highest level since 2018. That’s against a low base last year, but its operating profit grew from the previous quarter too, by 34%. A one-off gain from Samsung’s display segment—likely a guaranteed payment from Apple —helped. But the company’s semiconductor division was the main profit driver. Operating profit there more than doubled from a quarter earlier.

The chip shortage continues to help. Samsung not only sold more memory chips, but at higher prices. Component shortages, however, have hit the firm’s handset sales downstream.

Investors are already looking past the stellar quarter to the future: Samsung’s shares have lost 13% since January, partly reversing last year’s 45% gains. The main concern is whether the momentum of memory demand will continue. The component shortage could also further hurt end demand as manufacturers find it hard to ramp up production. Apple warned this week that supply constraints could hurt iPhone and iPad sales.

Work-from-home demand for personal computers may also start to fade as more people get vaccinated against Covid-19. And many manufacturers may have built big memory-chip inventories, which could presage a hangover down the road.

Samsung itself remains sanguine on the outlook. New smartphone launches—a new iPhone will likely come in the fall—as well as broader adoption of 5G could keep memory demand humming. The firm believes server and PC companies will remain strong buyers, too. Samsung says its chip inventory has fallen to a low level, which should help buoy prices.

There may also be positive surprises ahead. Samsung’s foundry business may garner more of investors’ focus. Potential acquisitions may help too: Samsung reiterated that it could make an acquisition of a meaningful size within three years. The company sat on the equivalent of $82 billion of net cash at the end of June.

Whether or not the memory-chip boom is peaking cyclically, Samsung looks well placed for the future.

Write to Jacky Wong at jacky.wong@wsj.com