Most brokerages require a Canadian residence, so when you depart, they will either freeze (I am not sure this is an option at all brokerages) or sell your positions, realizing any unrealized gain/loss, and thus you need to pay long/short term capital gain taxes on such gains held in taxable investment accounts. As far as I know, the length of your Canadian tax history is irrelevant.
No simple way to reduce this tax, you should consult a professional.