convert weight array from class member to local pointer to temporary storage
(cherry picked from commit ecbbdc2e7ff025d6ad1f6b808a13b2521ec825a8)