TST: Add test for pandas on sys.getsizeof GH#21758
diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py
index d31f617b9be15..4860ee235c03d 100644
--- a/pandas/tests/test_common.py
+++ b/pandas/tests/test_common.py
@@ -1,6 +1,8 @@
 import collections
 from functools import partial
 import string
+import subprocess
+import sys
 
 import numpy as np
 import pytest
@@ -229,3 +231,17 @@ def test_temp_setattr(with_exception):
                 raise ValueError("Inside exception raised")
         raise ValueError("Outside exception raised")
     assert ser.name == "first"
+
+
+def test_str_size():
+    # GH#21758
+    a = "a"
+    expected = sys.getsizeof(a)
+    pyexe = sys.executable.replace("\\", "/")
+    call = [
+        pyexe,
+        "-c",
+        "a='a';import sys;sys.getsizeof(a);import pandas;print(sys.getsizeof(a));",
+    ]
+    result = subprocess.check_output(call).decode()[-4:-1].strip("\n")
+    assert int(result) == int(expected)

- [ ] closes #21758 (Replace xxxx with the GitHub issue number)
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.
