diff --git a/AUTHORS.rst b/AUTHORS.rst
index d4eabed8..42b0f04b 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -87,3 +87,4 @@ Contributors (chronological)
 - Maxim Novikov `@m-novikov <https://github.com/m-novikov>`_
 - Viktor Kerkez `@alefnula <https://github.com/alefnula>`_
 - Jan Margeta `@jmargeta <https://github.com/jmargeta>`_
+- AlexV `@asmodehn <https://github.com/asmodehn>`_
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index f5dfb5d0..1cd2b3f6 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,13 @@
 Changelog
 ---------
 
+2.16.3 (unreleased)
++++++++++++++++++++
+
+Bug fixes:
+
+- Prevent memory leak when dynamically creating classes with ``type()``.
+
 2.16.2 (2018-10-30)
 +++++++++++++++++++
 
diff --git a/marshmallow/class_registry.py b/marshmallow/class_registry.py
index 0d7abbce..1cf585d0 100644
--- a/marshmallow/class_registry.py
+++ b/marshmallow/class_registry.py
@@ -48,11 +48,15 @@ def register(classname, cls):
     if classname in _registry and not \
             any(each.__module__ == module for each in _registry[classname]):
         _registry[classname].append(cls)
-    else:
+    elif classname not in _registry:
         _registry[classname] = [cls]
 
     # Also register the full path
-    _registry.setdefault(fullpath, []).append(cls)
+    if fullpath not in _registry:
+        _registry.setdefault(fullpath, []).append(cls)
+    else:
+        # If fullpath does exist, replace existing entry
+        _registry[fullpath] = [cls]
     return None
 
 def get_class(classname, all=False):

memory leak occurs when creating a new type
When I use the following code,  I observe that memory leak is very fast 
**MsgSchema = type('MsgSchema', (marshmallow.Schema,), {})**
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import marshmallow
import time
import psutil
import os

if __name__ == '__main__':
    pid = os.getpid()
    process = psutil.Process(pid)
    while True:
        MsgSchema = type('MsgSchema', (marshmallow.Schema,), {})
        mem = process.get_memory_info()[0]
        print("memory usage(%s):%d" % (pid, mem))
        time.sleep(0.01)
```
diff --git a/tests/test_registry.py b/tests/test_registry.py
index c4f61584..1f3c0be9 100644
--- a/tests/test_registry.py
+++ b/tests/test_registry.py
@@ -16,6 +16,66 @@ def test_serializer_has_class_registry():
     assert 'MySchema' in class_registry._registry
     assert 'MySubSchema' in class_registry._registry
 
+    # by fullpath
+    assert 'tests.test_registry.MySchema' in class_registry._registry
+    assert 'tests.test_registry.MySubSchema' in class_registry._registry
+
+
+def test_serializer_class_registry_register_same_classname_different_module():
+
+    reglen = len(class_registry._registry)
+
+    type('MyTestRegSchema', (Schema,), {'__module__': 'modA'})
+
+    assert 'MyTestRegSchema' in class_registry._registry
+    assert len(class_registry._registry.get('MyTestRegSchema')) == 1
+    assert 'modA.MyTestRegSchema' in class_registry._registry
+    #  storing for classname and fullpath
+    assert len(class_registry._registry) == reglen + 2
+
+    type('MyTestRegSchema', (Schema,), {'__module__': 'modB'})
+
+    assert 'MyTestRegSchema' in class_registry._registry
+    #  aggregating classes with same name from different modules
+    assert len(class_registry._registry.get('MyTestRegSchema')) == 2
+    assert 'modB.MyTestRegSchema' in class_registry._registry
+    #  storing for same classname (+0) and different module (+1)
+    assert len(class_registry._registry) == reglen + 2 + 1
+
+    type('MyTestRegSchema', (Schema,), {'__module__': 'modB'})
+
+    assert 'MyTestRegSchema' in class_registry._registry
+    #  only the class with matching module has been replaced
+    assert len(class_registry._registry.get('MyTestRegSchema')) == 2
+    assert 'modB.MyTestRegSchema' in class_registry._registry
+    #  only the class with matching module has been replaced (+0)
+    assert len(class_registry._registry) == reglen + 2 + 1
+
+
+def test_serializer_class_registry_override_if_same_classname_same_module():
+
+    reglen = len(class_registry._registry)
+
+    type('MyTestReg2Schema', (Schema,), {'__module__': 'SameModulePath'})
+
+    assert 'MyTestReg2Schema' in class_registry._registry
+    assert len(class_registry._registry.get('MyTestReg2Schema')) == 1
+    assert 'SameModulePath.MyTestReg2Schema' in class_registry._registry
+    assert len(class_registry._registry.get('SameModulePath.MyTestReg2Schema')) == 1
+    #  storing for classname and fullpath
+    assert len(class_registry._registry) == reglen + 2
+
+    type('MyTestReg2Schema', (Schema,), {'__module__': 'SameModulePath'})
+
+    assert 'MyTestReg2Schema' in class_registry._registry
+    #  overriding same class name and same module
+    assert len(class_registry._registry.get('MyTestReg2Schema')) == 1
+    assert 'SameModulePath.MyTestReg2Schema' in class_registry._registry
+    #  overriding same fullpath
+    assert len(class_registry._registry.get('SameModulePath.MyTestReg2Schema')) == 1
+    #  overriding for same classname (+0) and different module (+0)
+    assert len(class_registry._registry) == reglen + 2
+
 
 class A:
 

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.9
docs/requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.12
babel==2.17.0
cachetools==5.5.2
certifi==2025.1.31
chardet==5.2.0
charset-normalizer==3.4.1
colorama==0.4.6
distlib==0.3.9
docutils==0.21.2
exceptiongroup==1.2.2
filelock==3.18.0
flake8==3.6.0
idna==3.10
imagesize==1.4.1
iniconfig==2.1.0
Jinja2==3.1.6
MarkupSafe==3.0.2
-e git+https://github.com/marshmallow-code/marshmallow.git@45ef0512120520ee679875861e5c5cdacc16f8bf#egg=marshmallow
mccabe==0.6.1
packaging==24.2
platformdirs==4.3.7
pluggy==1.5.0
pycodestyle==2.4.0
pyflakes==2.0.0
Pygments==2.19.1
pyproject-api==1.9.0
pytest==8.3.5
python-dateutil==2.9.0.post0
pytz==2025.2
requests==2.32.3
simplejson==3.20.1
six==1.17.0
snowballstemmer==2.2.0
Sphinx==1.8.1
sphinx-issues==1.1.0
sphinx-version-warning==1.0.2
sphinxcontrib-serializinghtml==2.0.0
sphinxcontrib-websupport==1.2.4
tomli==2.2.1
tox==4.25.0
typing_extensions==4.13.0
urllib3==2.3.0
virtualenv==20.29.3

name: marshmallow
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.12
      - babel==2.17.0
      - cachetools==5.5.2
      - certifi==2025.1.31
      - chardet==5.2.0
      - charset-normalizer==3.4.1
      - colorama==0.4.6
      - distlib==0.3.9
      - docutils==0.21.2
      - exceptiongroup==1.2.2
      - filelock==3.18.0
      - flake8==3.6.0
      - idna==3.10
      - imagesize==1.4.1
      - iniconfig==2.1.0
      - jinja2==3.1.6
      - markupsafe==3.0.2
      - mccabe==0.6.1
      - packaging==24.2
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pycodestyle==2.4.0
      - pyflakes==2.0.0
      - pygments==2.19.1
      - pyproject-api==1.9.0
      - pytest==8.3.5
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - requests==2.32.3
      - simplejson==3.20.1
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==1.8.1
      - sphinx-issues==1.1.0
      - sphinx-version-warning==1.0.2
      - sphinxcontrib-serializinghtml==2.0.0
      - sphinxcontrib-websupport==1.2.4
      - tomli==2.2.1
      - tox==4.25.0
      - typing-extensions==4.13.0
      - urllib3==2.3.0
      - virtualenv==20.29.3
prefix: /opt/conda/envs/marshmallow

tests/test_registry.py::test_serializer_class_registry_register_same_classname_different_module tests/test_registry.py::test_serializer_class_registry_override_if_same_classname_same_module
tests/test_registry.py::test_serializer_has_class_registry tests/test_registry.py::test_two_way_nesting tests/test_registry.py::test_nesting_with_class_name_many tests/test_registry.py::test_invalid_class_name_in_nested_field_raises_error tests/test_registry.py::test_multiple_classes_with_same_name_raises_error tests/test_registry.py::test_multiple_classes_with_all tests/test_registry.py::test_can_use_full_module_path_to_class
CHANGELOG.rst marshmallow/class_registry.py AUTHORS.rst
CHANGELOG.rst marshmallow/class_registry.py AUTHORS.rst