Over the past two decades, it has been of great concern to solve the puzzle of social dilemmas in spatial public goods games. It has been demonstrated that the introduction of memory effects can effectively promote cooperative emergence to some extent. In this paper, we focus on the impact of scale-free and high aggregation properties on the public goods game of memory heterogeneous groups. Here, we propose an optimal strategy selection mechanism based on long-term historical payoffs. In our model, a memory loss function ω is introduced to characterize the memory length of players, and accordingly, pairs determine the optimal strategy by comparing historical gains for the next game cycle. Experiments conducted on scale-free networks and small world networks show that the strategy selection mechanism based on long-term payoff can keep the proportion of cooperators at a high level. In addition, this study demonstrates that the heterogeneity of memory length in the network promotes the enhancement of network reciprocity and robustness, which is beneficial to further reveal the mechanism of cooperative behaviour emergence in complex networks.