Minor refactoring and potential memory leak fix on GraphicResource.