Are you repeating the same code 30 times since the messages differ? Then, possibly, you could be facing this issue as strings gobble up memory pretty fast.

I would look at the feasibility of building subroutines that take the hubid and printing out messages that would be/could be common. That will bring in some reduction.

By your description, the picture is not entirely clear, so, I could be off on my diagnoses.