For example: Samba installed a lot of files in /usr/lib
and /usr/share
and other places.
Does running apt-get upgrade
delete the old versions of the Samba folders/files?
Of course it does. All files that are present in the package itself get updated when you update the package. This includes removal of obsolete files.
However, files that got created by the post-installation scripts will not be replaced or removed during a package update, unless it's specified in the pre-/post-installation scripts of the new version. They should get removed when you remove/purge the package later though.
Files created later while using the application (like user data, settings, cache, ...) are not maintained by the package manager though. If you purge a package, its removal scripts could take care of getting rid of those files, but don't necessarily have to. Stuff created in your home directory usually remains untouched.
However, all those installation/removal scripts are made by the package author and can include or miss commands to remove some files, depending on how thorough this person worked.
If you purge a package, its removal scripts should take care of geetting rid of those files.
does purge remove user settings?